Page 1 of 1

collision help

PostPosted: Sat Dec 31, 2011 10:03 pm
by heromedel
The tutorial on making a platfomer has you create a gravity like effect that lets you jump but fall back down. Problem is if you touch the side of any block you walk right into it and then fall through all the blocks. I have searched the forum, documentation and even looked at other peoples games and I cannot find a way to program a collision event that just stops you from walking through the blocks.

I really dont want to use regions or anything because then blocks can not be moved, unless each block had an exact same sized region.

So what I want is to be able to make an actor be able to jump on, walk on, and not walk through or jump through a block no matter what direction the actor is coming from. As in hit his head if jumping from below or just stop walking if he walks into it from the left or right.

The only thread I found talking about this was from 2004 and the question wasn't answered.

Re: collision help

PostPosted: Sat Dec 31, 2011 10:09 pm
by skydereign
There are plenty of threads on collision problems, not sure what you searched for, but this is usually one of the first thing people ask about. You'll need to have several collision events for the usual platformer collisions, and they all need to be on repeat enabled.
player -> Collision with top side of tiles (repeat enabled) -> Script Editor
Code: Select all
PhysicalResponse(MOVE_EVENT_ACTOR_ONLY, USE_CALCULATED_MASS, 1.000000,1.000000, 0, 0);
// you probably have something about jumping here
jump=1;


This is a collision with the walls. It preserves yvelocity, so you don't stick to the wall (because PhysicalResponse will change both x and yvelocity). So it stores the yvelocity, handles the collision, and sets the yvelocity back.
player -> Collision with left or right side of tiles (repeat enabled) -> Script Editor
Code: Select all
double yvel = yvelocity;
PhysicalResponse(MOVE_EVENT_ACTOR_ONLY, USE_CALCULATED_MASS, 1.000000,1.000000, 0, 0);
yvelocity=yvel;


Then you'll need one for the ceiling. All this one is stops the player from moving through the bottom of tiles.
player -> Collision with bottom side of tiles (repeat enabled) -> Script Editor
Code: Select all
PhysicalResponse(MOVE_EVENT_ACTOR_ONLY, USE_CALCULATED_MASS, 1.000000,1.000000, 0, 0);

Re: collision help

PostPosted: Sat Dec 31, 2011 10:27 pm
by heromedel
Thanks, for the quick response

Re: collision help

PostPosted: Sat Dec 31, 2011 10:36 pm
by heromedel
in line double yvel, what does double do? I looked it up and it seams to have something to do with float, or floating point numbes, but what effect is having on that line. is it changing yvel into a float number? is it not enough to set yvel as a real number?

I'm only asking so that I better understand how it works not just that it does.

Re: collision help

PostPosted: Sun Jan 01, 2012 12:14 am
by skydereign
Do you know what a variable is? A double is a type of variable that can store floating point. Since yvelocity has a floating point (it's not always an integer value) we want to create a variable that will preserve the decimal value. So, in that event, typing double declares a variable of type double, which stores yvelocity. The idea is that yvelocity won't be changed during the event, while xvelocity will be set to 0.

Re: collision help

PostPosted: Sun Jan 01, 2012 8:29 am
by heromedel
Yeah I know what a variable is, ok so it is making it a Floating point. Thanks.