Question about Collision side in script

Talk about making games.

Question about Collision side in script

Postby livens » Fri Feb 10, 2012 12:46 am

Hi all,

Im working on my first game ever. I had been making it a text based DOS game but when I found Game Editor I decided I could make it in a much better format.

I have a programming background, mostly C# and VB, but I do remember some of my C from college :) So Im trying to do most of the game logic there as opposed to spread out in the designer screens.

So my question is about the collision between my character and other actor objects. When A collision event happens and it triggers the script I want to get the 'side' that the collision is happening on. Like Top or Bottom, Right... Is there a function to get this info and use it in say a switch statement?

Thanks for helping out the new guy :)
livens
 
Posts: 13
Joined: Thu Feb 09, 2012 1:34 am
Score: 0 Give a positive score

Re: Question about Collision side in script

Postby skydereign » Fri Feb 10, 2012 1:10 am

Generally speaking no. gE does not provide a way of determining this in script. It does however allow you to break the collision into four separate events removing the need for the switch (though I know it'd be nice to have it in one event). You can come up with ways to guess the collision direction, by comparing x and y's and xvelocity and yvelocity's. It wouldn't however be perfect, but since you are wanting to use a single collision event, it may serve your purpose.
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: Question about Collision side in script

Postby livens » Fri Feb 10, 2012 2:20 am

Thanks skydereign,

I was afraid of that.

I was trying to keep the collision as simple as possible. RIght now I have a collision with any side of the walls do this:

Code: Select all
x = xprevious;
y = yprevious;


This works well enough for keeping the character from going through the walls. But it makes the walls sticky, pressing up against a wall you cannot go left or right without letting go of up. But if I knew what side I was colliding with I could release the 'y' or 'x' as needed to un-sticky the wall.
livens
 
Posts: 13
Joined: Thu Feb 09, 2012 1:34 am
Score: 0 Give a positive score

Re: Question about Collision side in script

Postby skydereign » Fri Feb 10, 2012 2:28 am

Usually what people do to prevent sticking is this (it uses PhysicalResponse though).
player -> Collision with Left/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.000000, 0.000000);
yvelocity = yvel;


player -> Collision with Top/Bottom side of tiles (repeat enabled) -> Script Editor
Code: Select all
double xvel = xvelocity;
PhysicalResponse(MOVE_EVENT_ACTOR_ONLY, USE_CALCULATED_MASS, 1.000000,1.000000, 0.000000, 0.000000);
xvelocity = xvel;
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: Question about Collision side in script

Postby livens » Fri Feb 10, 2012 3:32 am

skydereign wrote:Usually what people do to prevent sticking is this (it uses PhysicalResponse though).
player -> Collision with Left/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.000000, 0.000000);
yvelocity = yvel;


player -> Collision with Top/Bottom side of tiles (repeat enabled) -> Script Editor
Code: Select all
double xvel = xvelocity;
PhysicalResponse(MOVE_EVENT_ACTOR_ONLY, USE_CALCULATED_MASS, 1.000000,1.000000, 0.000000, 0.000000);
xvelocity = xvel;


:)

Wow, that works soooo much better! Thanks. It even handles a large hexagon shaped actor I have, letting my character slide off of the angles sides :)

But, you said: "(it uses PhysicalResponse though)", does that mean there is a downside to using the PhysicalResponse function that might crop up later in my game?

Youve helped me out alot, now I can move on to adding in the meat of the game.
livens
 
Posts: 13
Joined: Thu Feb 09, 2012 1:34 am
Score: 0 Give a positive score

Re: Question about Collision side in script

Postby skydereign » Fri Feb 10, 2012 4:26 am

Not really, some people here don't like to use it, and since you were not using PhysicalResponse in your code, I thought you might have been avoiding it (hence the though).
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score


Return to Game Development

Who is online

Users browsing this forum: No registered users and 1 guest