Specific sprite movement
-
I need help making a sprite move a certain way.
I want the left joystick to make the sprite point in a direction and then have the sprite always moving in the direction it’s pointing. But there is a catch I want the sprite to rotate at a certain speed so if the joystick is pointing down and you quickly move it up I want the sprite to take about a second to turn fully around.If any of that makes sense lol
-
assuming you are already keeping track of the rotation angle, maybe something like this
//keeping track angleTurn = 0 targetAngle = 0 lastAngle = 0 loop //code //check for input if angleTurn == 0 then targetAngle = input endif angleTurn += 0.1 //checks if there is still rotation to do //you might have to do something about negative rotation, won't work because of the <= if angleTurn < targetAngle - lastAngle then setSpriteRotation(sprite, lastAngle + angleTurn) else //resets the whole thing for the next time setSpriteRotation(sprite, targetAngle) angleTurn = 0 lastAngle = targetAngle endif //code repeat
hope it will be helpful in some way!
-
I think I might be able to figure something out with this I’ll give it a try now
-
So I got it to kind of work but there one issue. So it compares the rotation of the sprite to the position of the joystick and if the joystick is greater then it adds to the rotation of the sprite and it subtracts when it’s less but when it gets to 360 degrees and goes to 1 degree it turns all the way around in the wrong direction
-
@LinkCraft ok, that's confusing... maybe it has to do with the "end" of the circle (i.e. going back to 1 from 360)? I'm afraid I have no idea how to fix that though
-
Lol I’ll probably have to to something else thanks for the help though
-
@LinkCraft have you tried setspriteorigin to move the axis
-
@LinkCraft said in Specific sprite movement:
Lol I’ll probably have to to something else thanks for the help though
Could you friend share your code? It’s easier to spot the problem then...
-
This post is deleted! -
I made some changes to make it easer to understand but this is what I’m at so far
It sucks to get stuck in making a game from so early on lol
Planespeed = 10 Pr=0 Planeimg = loadimage(“plane”) Plane=createsprite() Setspriteimage(plane,planeimg) Setspritelocation(plane,gwidth()/2,gheight()/2) Setspritesvale(plane,{2,2}) Loop Clear(skyblue) C=controls(0) If (atan2(c.lx,c.ly)) < pr then Pr-=5 Endif If (atan2(c.lx,c.ly)) > pr then Pr+=5 Endif Setspriterotation(plane,Pr) Drawsprites() Update() Repeat
-
I’m trying to make a game like Man vs. Missiles if that helps.
-
-
You’ll probably want a ’desiredAngle’, ’currentAngle’, and ’turnspeed’ variables for your plane. It shouldn’t be too crazy hard to get it turning the right way. I bet there’s a smart-ass one-line trick that programmers know, but don’t worry if you figure out a dumb long clumsy way - as long as it works :)
-
I don’t care if it’s 100 lines I just want it to work Lol. I’ll check that link out later today Almost all websites are blocked on my phone (thankfully not fuze arena) and my dad uses the computer for work all day so I just have to wait until he’s done. :)
-
This post is deleted! -
@DomDom
Is that working? -
This post is deleted! -
Ok perfect all give it a go thanks so much
-
@DomDom Could you please just explain the code a little bit, and especially the use of the dot product?
I know it’s something I was taught in school, but it’s all a bit hazy...
-
This post is deleted!