The Daily Click ::. Forums ::. Klik Coding Help ::. distance/time = direct hit
 

Post Reply  Post Oekaki 
 

Posted By Message

HorrendousGames

Sourpuss

Registered
  31/10/2009
Points
  481

VIP MemberEvil klikerGame Of The Week Winner
6th December, 2010 at 08:26:14 -

I need a bit of help on this one. Basically I thought if I just divide the distance between two points by the time it should take to get there, then it should be somewhat accurate.
However, it's not. Basically all I want is just that, an object that travels from one point to another (both known) and there is a set time to get there, and it has to be dead on. and of course MMF2 doesn't seem to want to calculate floats in terms of XY movements.
I did the distance formula/time: speed = (Sqr(((x2-x1)*(x2-x1))+((y2-y1)*(y2-y1))))/time. I tried this with the bouncing ball movement, but prior to that I used XY movements, and in that case I had a separate X and Y speed (x2-x1)/time and (y2-y1)/time.
Both are extremely inaccurate, the XY movement won't move between numbers and the bouncing ball movement just blows something fierce. Also, i'd have to set up a very forgiving box for them to fit into, so it wouldn't miss/do one of those happy dances where it jumps around.

I might try resetting up on the XY and having another counter that counts down the steps it needs to get to the point, so once that counter reaches zero it stops moving, but I can already imagine it not working.

Solutions?

 
/-=?=-/-=?=-/-=?=-/-=?=-/-=?=-/-=?=-/-=?=-/-=?=-/-=?=-/-=?=-/-=?=-/-=?=-/-=?=-/-=?=-/-=?=-/-=?=-/-=?=-/-=?=-/-=?=-/-=?=-/-=?=-/-=?=-/
That Really Hot Chick
now on the Xbox Live Marketplace!

http://marketplace.xbox.com/en-US/Product/That-Really-Hot-Chick/66acd000-77fe-1000-9115-d80258550942

http://www.create-games.com/project.asp?view=main&id=2160

Duke Highway



Registered
  11/03/2010
Points
  21
6th December, 2010 at 11:09:46 -

One thing you could try is to use floats by multiplying your formula with 1.0
Then it should be accurate...

Edited by Duke Highway

 
n/a

Sketchy

Cornwall UK

Registered
  06/11/2004
Points
  1971

VIP MemberWeekly Picture Me This Round 43 Winner!Weekly Picture Me This Round 47 WinnerPicture Me This Round 49 Winner!
6th December, 2010 at 14:05:55 -

You just need to store the X and Y coordinates in alterable values (the built-in "x position" and "y position" can't hold floats, which is why your speed is getting rounded down).

+ whenever...
-> Object: XVel = (X("End") - X("Start")) / Time
-> Object: YVel = (Y("End") - Y("Start")) / Time

+ whenever...
-> Object: XPos = XPos + XVel
-> Object: YPos = YPos + YVel
-> Object: Set X position to XPos("Object")
-> Object: Set Y position to YPos("Object")

Edited by Sketchy

 
n/a

DeadmanDines

Best Article Writer

Registered
  27/04/2006
Points
  4758
6th December, 2010 at 17:12:19 -

And of course remember that when you're testing it with a bouncing ball, its speed is not in pixels per second, so it won't equate directly into the number of pixels travelled in a certain amount of time.

If you're using a custom movement and you maintain the floats by using Alterable Values as your variables, you should get it pixel perfect.

I used a similar formula for a space shooter where the player's ship projects a copy of itself 3 seconds in the future based on its current speed and angle, and warns of any obstacles within that path.

 
191 / 9999 * 7 + 191 * 7

HorrendousGames

Sourpuss

Registered
  31/10/2009
Points
  481

VIP MemberEvil klikerGame Of The Week Winner
6th December, 2010 at 18:50:45 -

That did the trick guys, It's not pixel perfect (barring the accurate representation of time I'm guessing) but it's at least not sticking in places and it hits right around the center of the crosshair (vs. somewhere in the vicinity/not moving on the Y at all).

@Duke - Great trick, I knew about this, but of course it doesn't work with built in XY values, but still good none the less.

@Sketchy - I always wondered why people stored their XY values in alterable values, and now I know two things. 1) More accurate like you described and 2) it's so much easier to copy/paste change the letter than right click, find the object, find the value, do stuff and a second time.

@Deadman dines - Yeah, I kind of figured that, even when changing around my representation of time, it still was really goofy.

Thanks a ton guys.

 
/-=?=-/-=?=-/-=?=-/-=?=-/-=?=-/-=?=-/-=?=-/-=?=-/-=?=-/-=?=-/-=?=-/-=?=-/-=?=-/-=?=-/-=?=-/-=?=-/-=?=-/-=?=-/-=?=-/-=?=-/-=?=-/-=?=-/
That Really Hot Chick
now on the Xbox Live Marketplace!

http://marketplace.xbox.com/en-US/Product/That-Really-Hot-Chick/66acd000-77fe-1000-9115-d80258550942

http://www.create-games.com/project.asp?view=main&id=2160
   

Post Reply



 



Advertisement

Worth A Click