Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

How do you create a trajectory/falling player?
Started by elifares Jun 24 2018 08:28 PM

- - - - -
3 replies to this topic
moveby deltaperframe trajectory falling gravity

Best Answer davebollinger , 25 June 2018 - 08:05 AM

if you're already using an enterFrame listener for x, then suggest you do same for y

fe here's a very basic Euler integrator:

local car = display.newRect( 20, 50, 20, 10 )

car.vx = 10 -- x-velocity, assumed to be instantaneous (ie, is already in effect)
car.vy = 0 -- y-velocity, none yet

car.ax = 0 -- x-acceleration, none (x-velocity is assumed to be already in effect)
car.ay = 1 -- y-acceleration, aka gravity

car.enterFrame = function(self, event)
  -- integrate position
  self.x = self.x + self.vx
  self.y = self.y + self.vy
  -- integrate velocity
  self.vx = self.vx + self.ax
  self.vy = self.vy + self.ay
end
Runtime:addEventListener("enterFrame", car)

[TOPIC CONTROLS]
This topic has been archived. This means that you cannot reply to this topic.
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

elifares

[GLOBAL: userInfoPane.html]
elifares
  • Enthusiast

  • 86 posts
  • Corona SDK

Hi,

 

Here is a screenshot of my game. I want the player to follow the outlined path. I am not using any physics, I was hoping I could achieve a close-enough gravity-like behaviour using easing. What I was hoping to do was to use deltaPerFrame on the player object to make them move right and then use transition.moveBy on the player object to make them go down using easing but I can't seem to make those 2 actions work at the same time.

 

I am using enterFrame to continuously update the player's deltaPerFrame in the x direction and I apply the moveBy transition once when the player collides with the cliff but what I am seeing is the moveBy transition runs first and then the deltaPerFrame kicks in after the moveBy transition is done even though I double checked that these two actions do happen at the same time. Does anyone know why that is? Can those 2 actions work at the same time?

Attached Thumbnails

  • Expected.png
  • reality.png


[TOPIC: post.html]
#2

roaminggamer

[GLOBAL: userInfoPane.html]
roaminggamer
  • Corona Geek

  • 7,666 posts
  • Corona SDK

In my observation, one can't really combine transition.* with  enterFrame.  They are always a little out of sync.

 

You'd be better served doing all the calculations and movements for this scenario in enterFrame, of by using a temporary body and physics.

 

If you do decide to use transition, you're going to need overlapping transitions to achieve that path.  You are aware you can call transition on an object multiple times in the same period, right?

 

Finally, I am not a big supporter of using anything but: transition.to() and transition.from()  I find using the other helper transition.* functions simply interferes with solving complex problems.  You can do everything you need with the two base functions.



[TOPIC: post.html]
#3

roaminggamer

[GLOBAL: userInfoPane.html]
roaminggamer
  • Corona Geek

  • 7,666 posts
  • Corona SDK

If you need help figuring out the math for the path, take a look at this example and take the code that draws the trajectory:

 

https://github.com/roaminggamer/RG_FreeStuff/blob/master/AskEd/2017/01/PredictingTrajectory.zip

 

I am not the author of this code.



[TOPIC: post.html]
#4

davebollinger

[GLOBAL: userInfoPane.html]
davebollinger
  • Corona Geek

  • 1,373 posts
  • Corona SDK

  Best Answer

if you're already using an enterFrame listener for x, then suggest you do same for y

fe here's a very basic Euler integrator:

local car = display.newRect( 20, 50, 20, 10 )

car.vx = 10 -- x-velocity, assumed to be instantaneous (ie, is already in effect)
car.vy = 0 -- y-velocity, none yet

car.ax = 0 -- x-acceleration, none (x-velocity is assumed to be already in effect)
car.ay = 1 -- y-acceleration, aka gravity

car.enterFrame = function(self, event)
  -- integrate position
  self.x = self.x + self.vx
  self.y = self.y + self.vy
  -- integrate velocity
  self.vx = self.vx + self.ax
  self.vy = self.vy + self.ay
end
Runtime:addEventListener("enterFrame", car)




[topic_controls]
[/topic_controls]