Skip to main content
gamedev.net
🔒 Locked

Effects match code please....

Started by gameplayprogammer 4 replies 850+ views
Original Post
gameplayprogammer
gameplayprogammer
i am trying to implement some cool motion effects, things like an object "sliding on ice and then coming to a stop effect" or "something being thrown at someone". Any math or c++ code would be helpful, nothing too complex :-). assume the object has an x,y starting position and knows the x,y destination to stop at.
h3ro
h3ro
Well, the simplest thing you can do is use linear interpolation between the start and stop position.
gameplayprogammer
gameplayprogammer
you mean just incrementing or decrementing the x and y till you get to the destination? tried that, it looks bad, was looking for a smooth gliding effect and then coming to a stop.
Evil Steve
Evil Steve
Quote:
Original post by gameplayprogammer
you mean just incrementing or decrementing the x and y till you get to the destination? tried that, it looks bad, was looking for a smooth gliding effect and then coming to a stop.
No, you change the amount you move based on the distance to the target.
Winegums
Winegums
since you know start, end, and current positions, you can find the scalar t that indicates the position on the trajectory line of the object reletive to the start and end.

Then you just apply some algorithm to weight the velocity of the object so it slows down over time (probably something like velocity = fullVelocity * t).

There's a thread on this page already about linear interpolation if you're not too sure about how it works.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.