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
@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.
function setup()
startPos={x=0,y=HEIGHT/2} -- start position
endPos={x=WIDTH,y=HEIGHT/2} --end position
duration=5; --how long it takes
end
function move()
tween(duration,startPos,endPos, -- time, start, end
{easing=tween.easing.linear,loop=tween.loop.once},done) -- tween type
end
function draw()
background(40, 40, 50)
fill(255)
sprite("Platformer Art:Guy Standing",startPos.x,startPos.y)
end
function touched(touch)
if touch.state == ENDED then
move()
end
end