I've tried using both cpBodyApplyImpulse and cpBodyApplyForce to make an object jump upwards, but it allways moves sideways.
Is this the way I'm supposed to do this or is there a better way?
How to make object jump?
-
- Posts: 28
- Joined: Tue Oct 02, 2007 5:02 am
- Contact:
- slembcke
- Site Admin
- Posts: 4166
- Joined: Tue Aug 14, 2007 7:13 pm
- Contact:
Re: How to make object jump?
Don't know why that would make the object move sideways.
I usually just do something like the following:
I usually just do something like the following:
Code: Select all
body->v.y += 20.0f
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
-
- Posts: 28
- Joined: Tue Oct 02, 2007 5:02 am
- Contact:
Re: How to make object jump?
Oh ok thanks, in the docs it says not to set those values explicitly so I did not bother trying - might want to update them.
I also had to make it so that the object only jumped when on land, which I did by using a collision pair function. (Maybe that might help someone in future, I don't know)
I also had to make it so that the object only jumped when on land, which I did by using a collision pair function. (Maybe that might help someone in future, I don't know)
- slembcke
- Site Admin
- Posts: 4166
- Joined: Tue Aug 14, 2007 7:13 pm
- Contact:
Re: How to make object jump?
Setting the position constantly is generally a bad idea. Setting the velocity can be fine if you are careful (cpBodyApplyImpluse() does nothing special in this regard). The problem is when you do something like this:X-0ut wrote:Oh ok thanks, in the docs it says not to set those values explicitly so I did not bother trying - might want to update them.
I also had to make it so that the object only jumped when on land, which I did by using a collision pair function. (Maybe that might help someone in future, I don't know)
Code: Select all
body->v.x = 100
Yeah, a collision function is the only good way to do it. You will also want to use the collision normal to determine if the player is touching a wall, the ceiling, or the floor.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
-
- Posts: 28
- Joined: Tue Oct 02, 2007 5:02 am
- Contact:
Re: How to make object jump?
Thanks, it all worked out great ![Smile :)](./images/smilies/icon_e_smile.gif)
![Smile :)](./images/smilies/icon_e_smile.gif)
Who is online
Users browsing this forum: No registered users and 21 guests