Jump to content

2.5D jumping code


YouGroove
 Share

Recommended Posts

Well i don't use character controller on player as i want only X/Y axes for 2.5D game.

 

I got some jumping code where i use AddForce on Y , and detect when Velocity go down from highter jump point reach in Y.

Than i detect when Velocity passes > 0 when character is beginning the first boucing , then i use SetPosition to cancel physics on character.and have it stay on floor instead of bounce.

 

 


function Script:Movement()

if self.jumping == 0 then
   pos = self.entity:GetPosition()

   Xplus=(App.window:KeyDown(Key.S) and 1 or 0)
   Xmoins=(App.window:KeyDown(Key.Q) and 1 or 0)
   playerx = (Xplus- Xmoins) * Time:GetSpeed() * self.moveSpeed

   if Xplus >0 then
       self.orient = 1
   end
   if Xmoins >0 then
       self.orient = -1
   end
   pos.x = pos.x + playerx

end


   jump=(App.window:KeyDown(Key.X) and 1 or 0)
   if self.jumping == 0 then
       if jump == 1 then
           self.jumping = 1
           self.entity:AddForce ( 0, 200, 0 , true )
       end
   end

if self.jumping == 1 then
       vel=self.entity:GetVelocity(true)
       if vel.y<0 then
       --    self.entity:AddForce ( 0, -50, 0 , true )
           self.jumping = 2
       end

end

if self.jumping == 2 then
       vel=self.entity:GetVelocity(true)
       if vel.y > 0 then
       --    self.entity:AddForce ( 0, -50, 0 , true )
           self.jumping = 0
           pos= self.entity:GetPosition()
           self.entity:SetPosition(pos)
       end  
end


   self.entity:PhysicsSetRotation( 0, 90*self.orient, 0 )

   -- move the controller in the rotation of the player
if self.jumping == 0 then
   self.entity:PhysicsSetPosition(pos.x,pos.y,self.zdepth,0.5)
end

end

 

The problem is that keeping pressed jump sometimes you can continuously jump ?

 

Just guess if someone have a working 2.5D lua code ?

Stop toying and make games

Link to comment
Share on other sites

ok then it should possible to ask for a linear velocity to the bottom (if player falls down)

 

if there is one you should disable the jump.

 

 

like:

 

is my player falling? yes -> disable jump

is my player falling? no -> enable jump

 

 

other solution:

 

if player have a collision with an entity with the key "ground" enable jump. if not disable jump.

It doesn´t work... why? mhmmm It works... why?

Link to comment
Share on other sites

THanks, bu it is some logic i followed, but i got strange stuuf happening, and trying debug crashed ?

Perhaps i'll try the key "groud", the problem is that i will need to attach script to each BSP ground, so it just complicated more the workflow :(

But seems the more secure way to do it for now.

Stop toying and make games

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...