It looks like you're new here. If you want to get involved, click one of these buttons!
In my project, when the player lifts his/her finger off the screen, I want the player to speed towards a sphere that’s in a different position from the player. But this comes with two problems. The first being that the player kinda moves off to the side and not towards the position of the sphere, and the second problem being that sometimes, the player will shoot up straight into the air and move at the same time, thus making the player fall off the map. Is there anyway to fix this???
Here’s the code I’m scratching my head on:
if touch.state == ENDED then
b.linearVelocity = vec3(lob.x - math.ceil((lob.x - 100)/12), lob.y - math.ceil((lob.y - 100)/12), lob.z - math.ceil((lob.z - 150)/12))
b.linearDamping = 0.4
b.friction = 2
end
Thanks in advance
Comments
@Creator27 You have to subtract the positions of the sphere and the player. That should give the amount (x,y,z) you give to the player to move towards the sphere.
@dave1707, do you mean something like this??
@Creator27 Here’s an example I have in 2D.
@dave1707, I tried using your code in Codea, but it came up with some errors. Do you have another example you could possibly show me?
Thanks