How to make a body jump while moving in an ellipse - Gideros Forum

#### Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

#### Top Posters

• ar2rsawseen 6991
• SinisterSoft 3812
• hgy29 2462
• keszegh 2055
• antix 2033
• OZApps 1983
• totebo 1764
• oleg 1574
• hgvyas123 1412
• techdojo 1321
• phongtt 1029
• Mells 1024
• MikeHart 1020
• john26 995
• GregBUG 962
• pie 960
• talis 908
• Scouser 898
• Apollo14 868
• MoKaLux 841

# How to make a body jump while moving in an ellipse

edited May 2014
I have given piece of code for a game that is to be played in landscape left mode. first piece of code is executed as soon as the player enters the frame and this results in motion of player along an ellipse. the code inside first else is executed when user touches the screen and at this moment I want the player to jump, and code inside second jump is executed when touch ends that is player gets back to initial position, please help me what shall be the code to make the player jump while in elliptical motion

if playertouch == false then
if playertouchend == false then
x = 215 + math.cos(angle)*195
y = 130 + math.sin(angle)*115
else
--code to jump here
end
else
--code to get back down

end

Likes: Yan

+1 -1 (+1 / -0 ) Share on Facebook

• To, jump, I need to use Z axis , right? or is it possible to do it alone using angle?, please? and it's possible only with z axis, how to do that, since setPosition allows only x, y psitions to set, help • Hi simran
Try this Code:(just copy it to main.lua)
-- You can jump by holding touch and back by release! (Sorry for my English )
application:setOrientation("landscapeLeft") -- good in 480*800

local xc = 400 -- X center of Ellipse
local yc = 200 -- Y center of Ellipse
local a = 400 -- big radius
local b = 100 -- small radius
local speed = 0.5 -- speed of rotating
local jump = 0
local maxjump = 50 -- can jump THIS pixel above
local jumpspeed = 1 -- speed of jumping

local theta = 0
local degree = math.pi / 180
local sinus = math.sin
local cosinus = math.cos

local sprite = gideros.class(Sprite)
function sprite:init()
self.jump = false
local mesh = Mesh.new()
mesh:setVertex(1,0,0)
mesh:setVertex(2,10,0)
mesh:setVertex(3,10,30)
mesh:setVertex(4,0,30)
mesh:setIndices(1,1,2,2,3,3,4,1,5,3,6,4)
mesh:setColorTransform(0.9,0,0,1)

end
function sprite:onEnterFrame()
if theta > 3600 then
theta = 3600 - theta
end
if self.jump and jump < maxjump then
jump = jump + jumpspeed
elseif jump > 0 then
jump = jump - jumpspeed
end

local angle = theta*degree
local x = xc + a * cosinus(angle)
local y = yc + b * sinus(angle) - jump
self:setPosition(x,y)
theta = theta + speed
end
function sprite:onTouchesBegin()
self.jump = true
end
function sprite:onTouchesEnd()
self.jump = false
end

mysprite = sprite.new()

• no, it did not work for me • what is exactly your problem? (don't be sad )
• Gideros is 2D gameEngine and there is no z axis here.
your body can jump in y axis (like most platform games)
• edited May 2014
@amin13a : Okay, no z axis, but I need a combination of x and y movement while it jumps,
this is what I am using for its motion in ellipse

x = 215 + math.cos(angle)*195
y = 130 + math.sin(angle)*115

Now, what shall i do to make the body jump while it is in motion along the ellipse, I want it to jump in the constraints of the ellipse.

• if jump means going further from center of ellipse (but remain on the elliptical path)
you can change my code by this order:

local jump = 1
local maxjump = 1.2 -- can jump THIS pixel above
local jumpspeed = 0.02 -- speed of jumping

local x = xc + a * cosinus(angle)* jump
local y = yc + b * sinus(angle) *jump
• Edit:
elseif jump > 0 then
must be changed by:
elseif jump > 1 then
• Following code worked, Thanks for your help ;D

if playertouch then
speed = 10
angle2 = 30
speedx = math.cos(20)
speedy = math.sin(130)
velocityx = speed*speedx
velocityy = speed*speedy
for i = 1, 1 do
x = x + velocityx
y = y + velocityy
self: setScaleY(1.8)
end

elseif playertouch == false then
for i = 1,1 do
x = x - velocityx
y = y - velocityy
x = 215 + math.cos(angle)*195
y = 130 + math.sin(angle)*115
self:setScaleY(1)
end
else
x = 215 + math.cos(angle)*195
y = 130 + math.sin(angle)*115
end