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.

AppGameKit Classic Chat / Has anyone got a function that would move a sprite across an arc please?

Author
Message
Kevin Cross
21
Years of Service
User Offline
Joined: 15th Nov 2003
Location: London, UK
Posted: 27th Oct 2017 21:15 Edited at: 27th Oct 2017 21:20
Has anyone got a function that would move a sprite across an arc / semi circle/ellipse please like the example I've attached as a video which will hopefully play without me needing to upload it to YouTube? What I've done is ok if it's all I can do but it would be good to get it to move exactly across the edge of the turn template which seems to create an ellipse instead of a proper circle. Here's the code I've used to move the sprite. The biggest problem I see with my example is that I'm going to struggle if the spaceship is at a totally different angle before it starts to turn. So for example if the ship is pointing right (90 degrees) and it turns right it will be turning down towards the bottom of the screen). At the moment I'm just playing around with something.





Sorry but I put all of my sprite functions into one so that's what the Orylia* functions do.

Maybe I need something that says move the sprite from x,y to x,y and change the angle by X, each step.

Attachments

Login to view attachments
Kevin Cross
21
Years of Service
User Offline
Joined: 15th Nov 2003
Location: London, UK
Posted: 27th Oct 2017 21:24
Having thought about it I think I've just answered my own question. A funtion that tweens the sprite from x,y to x,y but also tweens the angle.
Kevin Cross
21
Years of Service
User Offline
Joined: 15th Nov 2003
Location: London, UK
Posted: 27th Oct 2017 21:24
Having thought about it I think I've just answered my own question. A funtion that tweens the sprite from x,y to x,y but also tweens the angle.
Kevin Cross
21
Years of Service
User Offline
Joined: 15th Nov 2003
Location: London, UK
Posted: 27th Oct 2017 21:26
I may have trouble working out the x,y position to move to from wherever it's at and the angle etc.
Kevin Cross
21
Years of Service
User Offline
Joined: 15th Nov 2003
Location: London, UK
Posted: 28th Oct 2017 08:29
I was playing around a bit more and got a sprite moving along a path, tweening to different waypoints. Still a little way to go but it got me thinking about creating a utility/tool to create custom paths that can be loaded into a game. So will share that if I get anywhere with it. Couple of math problems I need to work on first.
Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 28th Oct 2017 09:41
me thought about using the sprite offset, then you rotate the sprite at circle center.
AGK (Steam) V2017.09.25 : Windows 10 Pro 64 Bit : AMD (17.9.3) Radeon R7 265 : Mac mini OS High Sierra (10.13)
Kevin Cross
21
Years of Service
User Offline
Joined: 15th Nov 2003
Location: London, UK
Posted: 28th Oct 2017 10:07
Genius Markus! I didn't think of setting the offset. I do set it in my example by setting it as the centre of the sprite but yes setting it to right of the sprite and a bit further should rotate the sprite around the offset which is a lot easier then sin and cos.

Thank you!

I probably will still look at the path setting tool as that may come in handy at a future date.
Richard_6
7
Years of Service
User Offline
Joined: 3rd Feb 2017
Location:
Posted: 28th Oct 2017 15:52
A path editor? Sounds very interesting! Been trying to make an infite (8) movement.



The outcome looks ok but then I will have to write one routine for every new shape. Thats why a path editor would be more suitable.
blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 28th Oct 2017 21:42
fubarpk
Retired Moderator
19
Years of Service
User Offline
Joined: 11th Jan 2005
Playing: AGK is my friend
Posted: 30th Oct 2017 04:38 Edited at: 30th Oct 2017 05:44
this may not move your sprite exactly like you want but it will send it from waypoint to waypoint
just add your waypoints click test and away you go a sprite that moves from way point to way point

simply store the waypoints in an array perhaps a json and then save them
you could also add an another algorithm to the movement that made things move in that formation
by storing the calculated x and y positions and calculating with those and using this to set the current location
fubar
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 30th Oct 2017 08:12
Rotating around an offset is OK, but is very limited. Is this for an object that will only follow the same path all of the time?

For example, in a racing game, a car may get shunted off its path. In this scenario, fubarpk's suggestion of waypoints becomes so much more desirable. With waypoints, you can continually readjust the path from where you are now (literally anywhere), to the waypoint.
You can also start to think about sin/cos etc to change the way you turn i.e looking more like a racing driver than a learner driver.

Next...combine with blink0k's suggestion of bezier curves. Now you have a path that you can get any point from, and use these as your waypoints.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Quidquid latine dictum sit, altum sonatur
TutCity is being rebuilt
Scraggle
Moderator
21
Years of Service
User Offline
Joined: 10th Jul 2003
Location: Yorkshire
Posted: 30th Oct 2017 08:45
FlowFields may also be an option depending on your particular requirements.
They take a little more initial set-up but then they are incredibly easy to use.
Kevin Cross
21
Years of Service
User Offline
Joined: 15th Nov 2003
Location: London, UK
Posted: 30th Oct 2017 17:53
I continued playing around with it some more and found I got a better result from using sin and cos. So for the problem I was experience I'm going to go with sin and cos like the first bit of code I posted in the first post. That works, although it isn't quite along the line.

I found the offset was causing me problems. Here's an example of the problem: if say the space ship was travelling up in a straight line and you want to turn right you have to use an offset to rotate it but that then re-positions the ship and makes it jump from it's original x position. What I couldn't get to work easily is to move the offset without moving the ship. I did muck about with switching from SetSpritePositionByOffset to SetSpritePosition at certain points but it was all a bit of a faff.

I also looked at joints as that seemed promising but when I rotated the fixed sprite (i.e. the invisible offset point) the ship didn't move. The fixed sprite did spin in it's place though.

This was all for a turn based game so it's not quite as complicated as a fast pace race game and the paths that might be required for that. And physics seem a little pointless in a slow paced turn based game

I still want to look at waypoints (maybe even for this project). I got something set up to place waypoints on the screen with a mouse click and have the sprite follow the path drawn. There's a few bits I need to implement, like being able to move the waypoints once placed, as well as delete and re-order them etc. I also want to draw a line between each point so you can see the path more clearly. I have it so that you can choose the duration of the tween and then that is divided by the number of points, however the problem with this is that if there's not an exact gap between each point some make the sprite move quicker or slower than the other points. What I think I need to do is measure the total distance between all points and then divide the tween duration time by that. In principle that seems like a good solution, and doable.

I've got some more ideas with this but I've pretty much only started it so it's hard to say where I get with it. I do want something that would export a text file that maybe contains an array and a function that can be copied and pasted into any project.

I haven't looked at any of your examples posted above yet as I'm at work and have been away from the forums for a day or two but will have a look through the examples soon to see what I can learn from them.

Thanks
Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 30th Oct 2017 18:12 Edited at: 30th Oct 2017 18:13
long ago i used a list of 4 point bezier curves for a track. moving along one bezier curve is just a value between 0 to 1.
i used pre calculated angles to get the car back at track, see screenshots.

blitzmax, Var = ref
p is the return value, TV2D is a Vector Type
AGK (Steam) V2017.09.25 : Windows 10 Pro 64 Bit : AMD (17.9.3) Radeon R7 265 : Mac mini OS High Sierra (10.13)

Attachments

Login to view attachments
fubarpk
Retired Moderator
19
Years of Service
User Offline
Joined: 11th Jan 2005
Playing: AGK is my friend
Posted: 31st Oct 2017 06:28 Edited at: 15th Nov 2017 02:29
Clonklex's Bevier Curve Library is great a great find blinkok
if you use Bezier Curve Library.agc
found here at the start of Clonkex thread
https://forum.thegamecreators.com/thread/210460

and then with the following changes to my above code
This now allows you to design a path save it and then load
it using an offset means you could for example have a particular alien
movement and then using the offset position anwhere on screen
main.agc

Clonklex's Bevier Curve Library


Plotting three points and selecting the Bezier curve option mimmicks your video
If you want to try the waypoints option ive added an offset testSpr.xOffset and testSpr.yOffset
they can be calculated by getting the difference from where you want the sprite and the location
they was first plotted and putting it in the offset variables arcs work with closed=0
If you wish to change closed to open or visa versa remember to clear after
Work to do make it so as you can have many different paths saved and load each one for
individual alien movements

fubar
tmu
7
Years of Service
User Offline
Joined: 2nd Feb 2017
Location:
Posted: 11th Nov 2017 14:37
Going with Markus's pics, I would ry to just plot some points long the path. Keep track which points the object has passed through. Target the next point in the list that has not been passed through. Set sprite angle always to face the point it is moving towards. Add minor randomness to make it look more sexy. That's just a hypothetical though ofcourse, never done it for this type of game. Used it to target stuff similarly and have enemies move towards player but not for some list of points. All these bezier curves and whatnot just sound complicated.

Login to post a reply

Server time is: 2024-11-24 05:51:04
Your offset time is: 2024-11-24 05:51:04