Jump to content


Photo

custom orbit script not working


  • Please log in to reply
5 replies to this topic

#1 spicydeath82

spicydeath82

    Awesomesauce

  • New Member
  • 138 posts
  • Version:GM8

Posted 07 July 2010 - 08:48 PM

this doesn't want to work...

/*
    Created by SpicyDeath82 / Opposing Forces Studios
    this script allows you to have an object orbit another object
    you place this in a step event(best in end step)
    orbit_object(object,dist,orbitspeed);

*/

object=argument0; // the object to orbit
dist=argument1; // this gets multiplied against the sprite's dimensions
orbitspeed=argument3; // use a negative value for reverse direction

x=object.x+lengthdir_x(object.sprite_width*dist,orbitspeed)
y=object.y+lengthdir_y(object.sprite_height*dist,orbitspeed)
all the orbiting object does is jump to the right of the object it's supposed to orbit.
how ever doing code snippets with this:
CREATE
orbitspeed=0;

STEP(end event)
orbitspeed=10;

x=object.x+lengthdir_x(object.sprite_width*dist,orbitspeed)
y=object.y+lengthdir_y(object.sprite_height*dist,orbitspeed)

the above works but isn't ideal as i want to use it as a simple script... any ides folks?

Edited by spicydeath82, 07 July 2010 - 08:50 PM.

  • 0

#2 treacheroust

treacheroust

    GMC Member

  • New Member
  • 74 posts

Posted 07 July 2010 - 11:05 PM

Should be like this. Good luck!
angle = point_direction(object.x, object.y, x, y);
angle += orbitspeed;
x=object.x+lengthdir_x(dist, angle);
y=object.y+lengthdir_y(dist, angle);

  • 0

#3 NakedPaulToast

NakedPaulToast

    GM Studio/Mac/Win

  • GMC Member
  • 7203 posts
  • Version:GM:Studio

Posted 07 July 2010 - 11:59 PM

orbitspeed=argument3; // use a negative value for reverse direction

orbitspeed=argument2; // use a negative value for reverse direction



And by the way if you're going to use a script, then you'd be wise to declare object, dist and orbitspeed as vars.

Edited by NakedPaulToast, 08 July 2010 - 12:04 AM.

  • 0

#4 ragarnak

ragarnak

    GMC Member

  • Retired Staff
  • 19468 posts
  • Version:GM8

Posted 08 July 2010 - 09:16 AM

this doesn't want to work... <snip code>

Well, thats quite easy to explain : you have a variable named "orbitspeed", but you are providing it as the "direction" argument in the "lengthdir_?(...)" commands.

In other words : you are not providing a speed, but an angle.

If you want to use speed you must also have a position somewhere (in this case an angle or direction) and update that position in every step.

Maybe like this :
//Create event
orbitAngle=0;   //Current position in the orbit
orbitSpeed=10;  //Rotation-speed (in degrees per step)

//step event
orbitAngle+=orbitspeed

x=object.x+lengthdir_x(object.sprite_width*dist,orbitAngle)
y=object.y+lengthdir_y(object.sprite_height*dist,orbitAngle)
Hope that helps.
  • 0

#5 spicydeath82

spicydeath82

    Awesomesauce

  • New Member
  • 138 posts
  • Version:GM8

Posted 11 July 2010 - 12:11 AM

i understand that lengthdir_? takes a direction as an argument.
but then why does the below code work perfectly fine?

CREATE
orbitspeed+=0;// or negative number

STEP(end event)
orbitspeed=10;

x=object.x+lengthdir_x(object.sprite_width*dist,orbitspeed)
y=object.y+lengthdir_y(object.sprite_height*dist,orbitspeed)

  • 0

#6 ragarnak

ragarnak

    GMC Member

  • Retired Staff
  • 19468 posts
  • Version:GM8

Posted 11 July 2010 - 08:45 AM

but then why does the below code work perfectly fine?

It doesn't.

You should get an error in the create-event (unknown variable), and the object will not move (you set it to 10 in every step).

Now if you would put the step-events contents in the create-event and the create-events contents in the step-event (swapping the contents) than it certainly would work.

I than have a single question remaining : why are you naming the variable "orbitspeed" when you are using it as an "orbitangle" (the actual "orbitspeed" is that "10" you are adding to it) ?
  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users