Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers DBPro Corner / make a sprite follow a path

Author
Message
jayell leedham
18
Years of Service
User Offline
Joined: 24th Jan 2006
Location: North Yorkshire
Posted: 20th Aug 2010 13:34
I have created an arrow in dbpro, showing the direction a ball (a sprite) should take I don't know how to make the ball move in that direction. Can anyone help please?
LBFN
17
Years of Service
User Offline
Joined: 7th Apr 2007
Location: USA
Posted: 20th Aug 2010 17:07 Edited at: 20th Aug 2010 17:12
Typically, a ball is moved using variables, which control the position of the sprite. Additional variables control the speed of the sprite on the x axis and the y axis. Here is a simple example:



So, if your arrow is pointing upward, you set Xspeed to 0 and ySpeed to -2 (or whatever negative number you want). If you want to go down and right, set Xspeed and Yspeed to the same positive number. Etc., etc.

So many games to code.......so little time.
jayell leedham
18
Years of Service
User Offline
Joined: 24th Jan 2006
Location: North Yorkshire
Posted: 20th Aug 2010 18:13
Thanks LBFN for your quick reply.
However, I didn't explain the problem properly.
I would like to send a ball from a to b, ie from x1,y1, to x2,y2.
jayell leedham
LBFN
17
Years of Service
User Offline
Joined: 7th Apr 2007
Location: USA
Posted: 20th Aug 2010 18:42
okay, this code creates a random point for the ball to go to and plots an 'X' there. The ball moves to this point.



So many games to code.......so little time.
jayell leedham
18
Years of Service
User Offline
Joined: 24th Jan 2006
Location: North Yorkshire
Posted: 20th Aug 2010 22:46
That's fine, but - the ball movement is, usually, like a dog's hind leg, whereas I would like tjhe ball to move in a straight line from its starting point to its destination.

Thanks for your patience...
jayell leedham
mikewhl
14
Years of Service
User Offline
Joined: 19th Jul 2010
Location: Columbus,Ohio
Posted: 21st Aug 2010 01:47
``````"like a dog's hind leg,"

LMAO!!!!!

I think he means "dogleg".

It moves like a Knight, he wants it to move like a Queen.

Mike

some cool stuff someone else said here
Rich Dersheimer
AGK Developer
15
Years of Service
User Offline
Joined: 1st Jul 2009
Location: Inside the box
Posted: 21st Aug 2010 03:31
This code makes a sprite move towards a target.



I'm sure the more mathematically inclined could give you a better formula.

jayell leedham
18
Years of Service
User Offline
Joined: 24th Jan 2006
Location: North Yorkshire
Posted: 21st Aug 2010 23:25
You're right! It was a dogleg. The maths are fine.
Thanks all, I can now get onto the next hurdle...
jayell leedham
jayell leedham
18
Years of Service
User Offline
Joined: 24th Jan 2006
Location: North Yorkshire
Posted: 26th Aug 2010 14:00
An update!
Using Rich Dersheimer's advice in his/her code snippet - angle#=ATAN((y1#-y2#)/(x1#-x2#)):rotate sprite 1,angle#:move sprite 1,.05
I can follow a given path with my sprite, no trouble.
However...
I would like to use point to see if the sprite collides with a wall, but I am told point does not work with sprites, even when I make point look well ahead on the path the sprite is taking.
How can I detect a wall therefore please?
Rich Dersheimer
AGK Developer
15
Years of Service
User Offline
Joined: 1st Jul 2009
Location: Inside the box
Posted: 26th Aug 2010 19:58
You can check sprite collisions with a somewhat fair degree of accuracy. Just make the wall a sprite too!

jayell leedham
18
Years of Service
User Offline
Joined: 24th Jan 2006
Location: North Yorkshire
Posted: 30th Aug 2010 15:09
Thanks Rich.
Making walls to be sprites works fine for collisions with vertical and horizontal walls.
However, how do you check collisions with diagonal walls, as such sprites are rectangular?

Login to post a reply

Server time is: 2024-09-28 22:39:01
Your offset time is: 2024-09-28 22:39:01