Using velocity to move one object towards another.
#1
This is mostly a math question, but how would one use FixedVelocity to move one object (In this case, a Circle) towards another (Player's body)?

I really want to finish my Chain Chomp ^_^
[Image: rogershanksluffy_display.gif]
Reply
#2
This is adapted from my gravity tool script. It hasn't been tested.

[lua]
force = 5
unitVector = box1.PositionConfusedub(box2).normalized --Get a vector with length 1 that points in the right direction
box1.FixedVelocity.Velocity = unitVector:mul(force) --Multiply it by the force to get the new velocity
[/lua]
Reply
#3
Thanks Jacob_! By making the force a negative, I managed to get it to work Tongue

By the way, I'm curious if there is a way to move it only one way (up or down). I am also curious as to what :mul() is.
[Image: rogershanksluffy_display.gif]
Reply
#4
If the x is 0, it will not affect x movement; same for y,

mul() returns a copy of the vector with the x and y components multiplied by the given value.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)