How do i make an object go twards another object with postion, without rotating the sprite?

I want an enemie that will always go in the direction of the player, but i do not know how to input the righ x and y values to go directly twards the player

2 Likes

You could use eases or the example in the help page. Also welcome to the community!

1 Like

I understand eases and all, but what if i need it to go the same rate of speed no matter the distance, while the player also moves

1 Like
2 Likes

You can extract the x and y from the player using the extractor and add a point at behavior (attach x and y) then add a timer with whatever delay and make it go forever with a 3 number connecting into a velocity behavior ( forward)

Try this:

{"data":{"behavior":{"v":"2","nodes":[{"inputCount":5,"outputCount":0,"name":"Follow Without Rotating","behaviorType":"logic.NodeGroup","x":90,"y":-32,"group":"","id":"17208011f2fb494b","isMenuItem":false},{"inputCount":0,"outputCount":1,"name":"Bundle Input","behaviorType":"logic.NodeGroupInput","x":0,"y":-32,"group":"17208011f2fb494b","id":"172134f64262bd4d","portId":"17208011f2fb494bi0","tag":"Speed","dataType":2},{"inputCount":0,"outputCount":1,"name":"Bundle Input","behaviorType":"logic.NodeGroupInput","x":0,"y":32,"group":"17208011f2fb494b","id":"172167295fa09342","portId":"17208011f2fb494bi1","tag":"On","dataType":2},{"inputCount":0,"outputCount":1,"name":"Bundle Input","behaviorType":"logic.NodeGroupInput","x":0,"y":96,"group":"17208011f2fb494b","id":"172196cab8278e4b","portId":"17208011f2fb494bi2","tag":"Off","dataType":2},{"inputCount":0,"outputCount":1,"name":"Bundle Input","behaviorType":"logic.NodeGroupInput","x":0,"y":160,"group":"17208011f2fb494b","id":"1721b8571a9ff34f","portId":"17208011f2fb494bi3","tag":"xTarget","dataType":2},{"inputCount":0,"outputCount":1,"name":"Bundle Input","behaviorType":"logic.NodeGroupInput","x":0,"y":224,"group":"17208011f2fb494b","id":"1721f513ac955d45","portId":"17208011f2fb494bi4","tag":"yTarget","dataType":2},{"inputCount":3,"outputCount":1,"name":"Switch","behaviorType":"logic.logic.Switch","x":180,"y":288,"group":"17208011f2fb494b","id":"172242279097af4d","_startVal":1,"dataType":2},{"inputCount":0,"outputCount":1,"name":"Always","behaviorType":"logic.triggers.Always","x":0,"y":352,"group":"17208011f2fb494b","id":"17227aa8aec8cf4b"},{"inputCount":1,"outputCount":1,"name":"Extractor","behaviorType":"logic.properties.Extractor","x":360,"y":320,"group":"17208011f2fb494b","id":"1723216c25255d49","targetId":0,"prop":"x","version":2},{"inputCount":1,"outputCount":1,"name":"Extractor","behaviorType":"logic.properties.Extractor","x":360,"y":416,"group":"17208011f2fb494b","id":"17232e6fa610dd4b","targetId":0,"prop":"y","version":2},{"expression":"A-B","default0":0,"default1":0,"default2":0,"default3":0,"default4":0,"default5":0,"params":2,"version":2,"tag":"X Distance","inputCount":3,"outputCount":1,"name":"Expression","behaviorType":"logic.logic.Expression","x":540,"y":224,"group":"17208011f2fb494b","id":"17236a0851dafc40"},{"expression":"A-B","default0":0,"default1":0,"default2":0,"default3":0,"default4":0,"default5":0,"params":2,"version":2,"tag":"Y Distance","inputCount":3,"outputCount":1,"name":"Expression","behaviorType":"logic.logic.Expression","x":540,"y":352,"group":"17208011f2fb494b","id":"1723a385a794ad4a"},{"expression":"Math.min(A,(Math.sqrt((A*A)+(B*B))))","default0":1,"default1":0,"default2":0,"default3":0,"default4":0,"default5":0,"params":3,"version":2,"tag":"Max Forward Speed","inputCount":4,"outputCount":1,"name":"Expression","behaviorType":"logic.logic.Expression","x":720,"y":192,"group":"17208011f2fb494b","id":"1725452882ac7142"},{"expression":"Math.atan2(B,A)","default0":0,"default1":0,"default2":0,"default3":0,"default4":0,"default5":0,"params":2,"version":2,"tag":"Angle To Target (Radians)","inputCount":3,"outputCount":1,"name":"Expression","behaviorType":"logic.logic.Expression","x":720,"y":320,"group":"17208011f2fb494b","id":"172943dae2f76e4d"},{"expression":"(Math.cos(B))*A","default0":0,"default1":0,"default2":0,"default3":0,"default4":0,"default5":0,"params":2,"version":2,"tag":"X Velocity","inputCount":3,"outputCount":1,"name":"Expression","behaviorType":"logic.logic.Expression","x":900,"y":224,"group":"17208011f2fb494b","id":"1729ebb16fd02242"},{"expression":"(Math.sin(B))*A","default0":0,"default1":0,"default2":0,"default3":0,"default4":0,"default5":0,"params":2,"version":2,"tag":"Y Velocity","inputCount":3,"outputCount":1,"name":"Expression","behaviorType":"logic.logic.Expression","x":900,"y":320,"group":"17208011f2fb494b","id":"172af87d7c795748"},{"inputCount":3,"outputCount":3,"name":"Velocity","behaviorType":"logic.properties.Physics","x":1080,"y":288,"group":"17208011f2fb494b","id":"172bd79e03fcc04d"}],"links":[{"input_id":"1725452882ac7142i0","output_id":"172134f64262bd4do0"},{"input_id":"172242279097af4di1","output_id":"172167295fa09342o0"},{"input_id":"172242279097af4di0","output_id":"172196cab8278e4bo0"},{"input_id":"17236a0851dafc40i0","output_id":"1721b8571a9ff34fo0"},{"input_id":"1723a385a794ad4ai0","output_id":"1721f513ac955d45o0"},{"input_id":"1723216c25255d49i0","output_id":"172242279097af4do0"},{"input_id":"17232e6fa610dd4bi0","output_id":"172242279097af4do0"},{"input_id":"172242279097af4di2","output_id":"17227aa8aec8cf4bo0"},{"input_id":"17236a0851dafc40i1","output_id":"1723216c25255d49o0"},{"input_id":"17236a0851dafc40i2","output_id":"1723216c25255d49o0"},{"input_id":"1723a385a794ad4ai1","output_id":"17232e6fa610dd4bo0"},{"input_id":"1723a385a794ad4ai2","output_id":"17232e6fa610dd4bo0"},{"input_id":"1725452882ac7142i1","output_id":"17236a0851dafc40o0"},{"input_id":"172943dae2f76e4di0","output_id":"17236a0851dafc40o0"},{"input_id":"1725452882ac7142i2","output_id":"1723a385a794ad4ao0"},{"input_id":"1725452882ac7142i3","output_id":"1723a385a794ad4ao0"},{"input_id":"172943dae2f76e4di1","output_id":"1723a385a794ad4ao0"},{"input_id":"172943dae2f76e4di2","output_id":"1723a385a794ad4ao0"},{"input_id":"1729ebb16fd02242i0","output_id":"1725452882ac7142o0"},{"input_id":"172af87d7c795748i0","output_id":"1725452882ac7142o0"},{"input_id":"1729ebb16fd02242i1","output_id":"172943dae2f76e4do0"},{"input_id":"1729ebb16fd02242i2","output_id":"172943dae2f76e4do0"},{"input_id":"172af87d7c795748i1","output_id":"172943dae2f76e4do0"},{"input_id":"172af87d7c795748i2","output_id":"172943dae2f76e4do0"},{"input_id":"172bd79e03fcc04di0","output_id":"1729ebb16fd02242o0"},{"input_id":"172bd79e03fcc04di1","output_id":"172af87d7c795748o0"}]}}}

The xTarget and yTarget would be inputs for player X and Y.

Basically it uses trigonometry to calculate the needed X and Y velocities.

Btw SWIG copy and paste the code in the grey box into the import

This converts direction into x and y velocity so you can have directional velocity without needing to turn the sprite.
Flowlab Game Creator - Angle To Velocity