[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 112: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 112: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions.php on line 4762: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3897)
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions.php on line 4764: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3897)
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions.php on line 4765: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3897)
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions.php on line 4766: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3897)
Chipmunk Physics • View topic - Dynamic Object Floating Through Static Object

Dynamic Object Floating Through Static Object

Official forum for the .

Dynamic Object Floating Through Static Object

Postby hmcgames12 » Thu Jul 05, 2012 7:00 pm

hmcgames12
 
Posts: 6
Joined: Thu Jul 05, 2012 6:46 pm

Re: Dynamic Object Floating Through Static Object

Postby slembcke » Thu Jul 05, 2012 11:43 pm

You cannot move a static body (it wouldn't be static if it moved). By telling Chipmunk that a body is static, you are saying that it's collision detection information should never need to be recalculated and that it's safe for objects to fall asleep when they touch it. It is possible to notify Chipmunk that a static shape has move using one of the following cpSpace functions though. http://chipmunk-physics.net/release/Chi ... alIndexing If you are moving the static shape every frame, you should be using a rogue body instead however.

Also, you are only setting the position of the body when you move it. That's going to make the physics of the platform work very poorly. Read here for an explanation of why: viewtopic.php?f=4&t=2227
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
User avatar
slembcke
Site Admin
 
Posts: 4164
Joined: Tue Aug 14, 2007 7:13 pm

Re: Dynamic Object Floating Through Static Object

Postby hmcgames12 » Fri Jul 06, 2012 1:53 pm

Hello Slembcke,

Thank you for your response! I believe that I described my problem poorly/my code reflects it poorly, however. We never try to move the platform - it indeed remains static - but for some reason if we do not include an update function, the sprite does not display properly on the screen. But that's another problem entirely.

Also, we have a main update loop that is called periodically, so the positions of the characters and platforms are actually updated often (not just when the objects are moved).

The only part of the collision we are concerned about is that the main character (a dragon) does not "hit its head" on the platform when it jumps from underneath it. The platform stays still in all frames, as it should, but the dragon goes up through the platform instead of hitting its head on the platform and falling down. Basically, the collision between the static and the dynamic object is detected, as it should be, but the dynamic object is not reacting properly. How can we fix this (so that the dragon falls down after hitting the bottom of the platform rather than "falling up"?)

Thanks again!
hmcgames12
 
Posts: 6
Joined: Thu Jul 05, 2012 6:46 pm

Re: Dynamic Object Floating Through Static Object

Postby slembcke » Fri Jul 06, 2012 2:02 pm

Oh. Derp. I read the update method too quickly and misread it. Never mind about that.

I'm not really sure what would be causing your issues then. What does your jump function look like?
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
User avatar
slembcke
Site Admin
 
Posts: 4164
Joined: Tue Aug 14, 2007 7:13 pm

Re: Dynamic Object Floating Through Static Object

Postby hmcgames12 » Fri Jul 06, 2012 2:17 pm

hmcgames12
 
Posts: 6
Joined: Thu Jul 05, 2012 6:46 pm

Re: Dynamic Object Floating Through Static Object

Postby slembcke » Mon Jul 09, 2012 8:58 am

Ah. I suspected something like that.

So by applying the velocity and setting the position yourself, you are basically undoing all the work that the physics engine is doing. When it collides with the platform and stops its upward movement, you are continuing to push it into the platform anyway. It's trying to keep it out of the platform, but you are overwriting it's position and using a velocity that doesn't match the one Chipmunk is using.

The simplest way to make a character jump is to just "toss" them into the air by changing the velocity over one frame. playerBody->v.y = 100 or something similar. This is very simplistic though and I'm guessing not what you are looking for. I made some very complete platformer controls for a contest game last year. You can find the source code here:
https://github.com/maximile/Your-Story/ ... haracter.m
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
User avatar
slembcke
Site Admin
 
Posts: 4164
Joined: Tue Aug 14, 2007 7:13 pm

Re: Dynamic Object Floating Through Static Object

Postby hmcgames12 » Mon Jul 09, 2012 12:57 pm

Ah yes, that was the problem exactly! Thank you so much, Slembcke!
hmcgames12
 
Posts: 6
Joined: Thu Jul 05, 2012 6:46 pm


Return to Chipmunk2D Physics

Who is online

Users browsing this forum: No registered users and 6 guests

cron