How to shoot animation from point A to point B

The Partridge Family were neither partridges nor a family. Discuss.
Post Reply
Ferbguy
Posts: 51
Joined: August 29th, 2012, 10:54 pm
Location: Georgia

How to shoot animation from point A to point B

Post by Ferbguy » November 27th, 2012, 11:34 pm

I am working on a game. Im kinda stumped atm, having issues on grasping how to shoot a Animation shot from object 1 to object 2 where object 2 is changing slowly moving towards the nearest object 1. i am trying to draw a invisible line from object 1 to object 2 current position and play the animation along that invisible line. Am i even in the right nieghborhood.

Musi
Posts: 106
Joined: November 25th, 2012, 1:06 am

Re: How to shoot animation from point A to point B

Post by Musi » November 28th, 2012, 12:47 am

I know y = m*x + b is the formula to find a straight line between 2 points but i'm not really sure if it would work for sprite movement. Chili explains it in lesson 10.

Though using trigonometry SOH CAH TOA you can get a direction from one point to another and move the shot the exact distance you want in that direction.

In fact I'm going to see if i can write a function that takes in 2 coordinates and finds the angle and distance between them, just for fun.
Musi

There are 10 types of people that understand binary.
Those that do, and those that don't.

Musi
Posts: 106
Joined: November 25th, 2012, 1:06 am

Re: How to shoot animation from point A to point B

Post by Musi » November 28th, 2012, 9:11 pm

Well, i really did try but i can't get it to work. i wrote a function to move one point towards another with a variable speed, it compiled fine but broke when i ran it. Then while debugging, whenever i try to step into the function is tells me the source code is missing and i have no idea why.
Musi

There are 10 types of people that understand binary.
Those that do, and those that don't.

User avatar
chili
Site Admin
Posts: 3948
Joined: December 31st, 2011, 4:53 pm
Location: Japan
Contact:

Re: How to shoot animation from point A to point B

Post by chili » November 29th, 2012, 2:14 pm

Seems simple enough. Take the x and y distances and divide them by the number of frames you want the animation to last. Then add these values to you position for n frames, after which your object will be at its destination. Make sure you use floats and use logical rounding.
Chili

Ferbguy
Posts: 51
Joined: August 29th, 2012, 10:54 pm
Location: Georgia

Re: How to shoot animation from point A to point B

Post by Ferbguy » November 30th, 2012, 12:17 am

ok, i am going to try and see if i can get this to play from that angle, also one more thing, object a uses animation to simulate rotation bases off of mouse coords, use the same thing for both?

User avatar
LuX
Posts: 1492
Joined: April 22nd, 2012, 12:33 pm
Location: Finland

Re: How to shoot animation from point A to point B

Post by LuX » November 30th, 2012, 8:28 pm

Interesting, haven't thought about chili's method before.
ʕ •ᴥ•ʔ

Post Reply