Orient object's rotation to path

A

Alex_Beach

Guest
Is there a way to make an object rotate as it goes along the path's curvature? For instance, if a path curves up, then the object will curve up as it hits that part of the path. Also, my objects have 0 speed, so can this be done without using the direction from speed relationship?

Edit: by rotation, I mean image_angle
 
Last edited by a moderator:

Bingdom

Googledom
You can do this quite easily if your object is moving.

newPos - oldPos
Then use point_direction to get your direction.
(Or you could skip the minus and apply the coordinates to point_dir directly)

If your object is not moving, there's a function that returns the path's coords depending on what point of the path you want (you will still need 2 points). Same math applies using this approach.

I haven't yet looked at getting the direction from a point directly, but this is what I can come up with from memory.
 
Last edited:
G

Gronbal

Guest
I can only think of one way of doing this at the moment. This would be to make an invisible object who runs on the same path a little in front of the object, which you want to change orientation of. By this method you can change the orientation of the object based on the invisible objects position.

You can then calculate the image_angle with something like this:
Code:
image_angle = point_direction(x, y, obj_invis.x, obj_invis.y);
 
A

Alex_Beach

Guest
I can only think of one way of doing this at the moment. This would be to make an invisible object who runs on the same path a little in front of the object, which you want to change orientation of. By this method you can change the orientation of the object based on the invisible objects position.

You can then calculate the image_angle with something like this:
Code:
image_angle = point_direction(x, y, obj_invis.x, obj_invis.y);
This is a nice idea. I tried this and image_angle always returns 0. The invisible object is behind the visible one on the path, but I think their distances apart are lower than a whole pixel. Would normalizing the vector solve this?
 

Bingdom

Googledom
Why do I occasionally get ignored? :(

No, you don't need an object for this. You're making things harder. Now you need to ensure both objects are running on the same path and have a slightly different offset (Which I think is your current problem - no offset).

Why not store a position to a variable? Set the position after you got the angle. Like I mentioned in my post. Alternatively, you can get the next position by having a slight offset from your path's current progress. Like I said, there are functions out there that can give you the x/y from the path, depending on the progress. A quick look at the paths section of the manual will give you this.
 

Bingdom

Googledom
I found another post which seems to have solved this problem!

Post:
https://forum.yoyogames.com/index.p...ace-the-right-direction-when-on-a-path.19243/

As I can see an instance traveling on a path will have a given direction, stored in the function direction. image_angle can therefor be set directly to the direction function. I just skimmed the post, you might want to read it through. :)
From memory, the convenient built in variables don't work with paths (for hspeed and vspeed at least, thus speed and direction shouldn't work either).

They may have added it in gms2. I'm not sure.
 
D

danielfsantos

Guest
You could just create an object, and when it collides, change the image angle :)
 
Top