Precise collision and other question.

Talk about making games.

Precise collision and other question.

Postby Hammerit » Mon Feb 03, 2014 12:14 pm

Hello everyone.
I am trying to do some sort of platform game. And i have several questions.
1.How do i get properties of collide object?
My Actor collide with a tile, i want to get coordinates of this tile, but when i use COLLIDE ACTOR i get coordinates for the massive of tiles.
2.Where is coordinate point in actor? Is it in the center?
3.On the picture my speed more then distance,in the next step i want Actor to be near wall, how do i do that?
And i don't want to add PHYSICAL RESPONSE because it makes hero stuck in the wall, when i pushing right.
I could do it in 3 steps but it looks not good.
Attachments
Collision.png
Hammerit
 
Posts: 12
Joined: Sun Feb 02, 2014 9:52 pm
Score: 2 Give a positive score

Re: Precise collision and other question.

Postby DeltaLeeds » Mon Feb 03, 2014 3:27 pm

1. Do you want the coordinates printed or something? Well, if you just need to know how to get the coordinates of the collide actor, use collide.x,collide.y.
2. Try clicking it. It'll show fixed coordinates. That is the coordinates.
3. To make it move right.
Code: Select all
x+=5

If you want it to move left, make the + to -.
If you want it to stop when touching the actor. Try:
Code: Select all
if(x==<Actor>.x)
{
    if(y==<Actor>.y)
    {
         collide.directional_velocity=directional_velocity;
         directional_velocity--;//Not sure if this works though. I'll test it.
    }
}


I'm never used to helping people, but I tried. If it doesn't work. I'll find a way to solve it.
Currently: Semi-Active.
Working on: Maybe putting my test games in gamejolt, polishing them a bit, but I still don't know when.
User avatar
DeltaLeeds
 
Posts: 693
Joined: Fri May 06, 2011 12:45 pm
Location: In front of my computer.
Score: 38 Give a positive score

Re: Precise collision and other question.

Postby Hares » Mon Feb 03, 2014 6:35 pm

1. I don't know how to get the coordinates of a single tile. I would like to see that one answered too.

2. Yes, GE uses the center of the actor for coordinates. (For view the coordinates are the top left corner)

3. I would suggest using PHYSICAL RESPONSE anyway.
To prevent the player from sticking to the wall you can do this:
First you make a variable that stores the yvelocity of the player, before the physical response.
And after the physical response you set the stored value back to the real yvelocity.

Code: Select all
player_yvel=yvelocity;
PhysicalResponse(MOVE_EVENT_ACTOR_ONLY, USE_CALCULATED_MASS, 1, 1, 0, 0);
yvelocity=player_yvel;

The trick to not sticking to the wall can be found elsewhere on the forum too. Try doing a search on "sticky walls".
User avatar
Hares
 
Posts: 105
Joined: Fri Dec 20, 2013 8:39 pm
Location: Belgium
Score: 14 Give a positive score

Re: Precise collision and other question.

Postby lcl » Mon Feb 03, 2014 7:25 pm

@Hares:
That's a good basic code. However, there's one thing you forgot to wrote.
The variable player_yvel has to first be declared. In this case we want the variable to be a floating point number, so we use the keyword double to declare it.
Here's the correct code:
Code: Select all
double player_yvel=yvelocity;
PhysicalResponse(MOVE_EVENT_ACTOR_ONLY, USE_CALCULATED_MASS, 1, 1, 0, 0);
yvelocity=player_yvel;

What this code does is to create a local (temporary) floating point variable named player_yvel and sets it equal to the actor's yvelocity.
then happens the physical response, and then the actor's yvelocity is retrieved by setting it equal to player_yvel which has the value of the actor's yvelocity before the physical response, which sets the yvelocity to 0.
User avatar
lcl
 
Posts: 2339
Joined: Thu Mar 25, 2010 5:55 pm
Location: Finland
Score: 276 Give a positive score

Re: Precise collision and other question.

Postby Hammerit » Mon Feb 03, 2014 8:02 pm

Thank you for the answers!
I FIGURED OUT!
What i have done:
1.Made custom single picture for single tile.
2.Didn't use tile function to create level.
3.Used clone function to create level.
4.Then I added collision event for right side of this tile.
Code: Select all
if ( (collide.x - hero.x) >= 0) //checks if collision from right side
{
   hero.x=(collide.x-(hero.width+collide.width)/2); // calculates new position for hero from right side of a wall
}
else
{
   hero.x=(collide.x+(hero.width+collide.width)/2); // calculates new position for hero from left side of a wall
};

So what problem i had?
I used tiles to create level.
After several testing i found out.
Actor.width and height gives width and height FOR ALL ANIMATION. That means it doesn't give width and height of used FRAME, but give width for all frames in total.
Coordinates for collide object were strange us well.
And then i figure out that game edit makes invisible IMAGE OF THE ANIMATION AND MAKE IT PARENT FOR ALL TILES. And collide object calculates coordinates from it.
On the picture i marked invisible image of animations.
Attachments
HMMMMmmm.png
Hammerit
 
Posts: 12
Joined: Sun Feb 02, 2014 9:52 pm
Score: 2 Give a positive score

Re: Precise collision and other question.

Postby Hammerit » Mon Feb 03, 2014 9:16 pm

It's working somewhat...
What this code does is to create a local (temporary) floating point variable named player_yvel and sets it equal to the actor's yvelocity.
then happens the physical response, and then the actor's yvelocity is retrieved by setting it equal to player_yvel which has the value of the actor's yvelocity before the physical response, which sets the yvelocity to 0.

Isn't it suppose to bounce hero?
PhysicalResponse(MOVE_EVENT_ACTOR_ONLY, USE_CALCULATED_MASS, 1, 1, 0, 0);
So what exactly doest it do? Does it puts my hero before collision and makes yvelosity = 0?
Attachments
mygame.zip
(76.81 KiB) Downloaded 187 times
Hammerit
 
Posts: 12
Joined: Sun Feb 02, 2014 9:52 pm
Score: 2 Give a positive score

Re: Precise collision and other question.

Postby Hammerit » Tue Feb 04, 2014 10:42 am

Hello again. Using advice i made test platform game using PhysicalResponse, where character move and jump.
And found out several problems while using this method:
1."Suicide" moving and jumping.
If hero stand near ledge he will move until he fall from the ledge. If he will hit block on top he will move also.
2. Tile climbing.
If hero jumps on platform and don't have enough speed to reach it he will "climb" it.
The reason, why hero do that, is because PhysicalResponse recalculate hero position using angles, moving hero left or right, up or down.(maybe i wrong.)

I look on several games made by people many of them have the same problem...So how to solve this or just roll with it?
Attachments
test2.zip
(85.82 KiB) Downloaded 185 times
Hammerit
 
Posts: 12
Joined: Sun Feb 02, 2014 9:52 pm
Score: 2 Give a positive score

Re: Precise collision and other question.

Postby Hares » Tue Feb 04, 2014 7:41 pm

@lcl
Thanks for correcting my previous post

@Hammerit
If you stand near the edge the hero will slowly move to the edge, and fall off:
For this I haven't found an easy solution yet.
Personally I just roll with it :)

Tile climbing:
In your test file I noticed that you also use the sticky walls principle for the top/bottom collision.
If you change your code for top/bottom collision, the hero will not climb the walls anymore when he can not jump high enough.
Use one collision event for hero collision with ground TOP - repeat yes
Code: Select all
PhysicalResponse(MOVE_EVENT_ACTOR_ONLY, USE_CALCULATED_MASS, 1.000000, 1.000000, 0.000000, 0.000000)

And use another collsion for hero collision with ground BOTTOM - repeat yes
Code: Select all
hero.yvelocity=1;

You could also use 0 zero for yvelocity in the above code.

When you walk agains a wall, the hero start shaking on the vertical axis.
To prevent this I set up a variable that changes value when the player is jumping.
On the hero collison with ground left or right side event, I add an if statement.
If the player is jumping use the code you already use.
If the player is not jumping use
Code: Select all
hero.y=hero.yprevious
User avatar
Hares
 
Posts: 105
Joined: Fri Dec 20, 2013 8:39 pm
Location: Belgium
Score: 14 Give a positive score

Re: Precise collision and other question.

Postby Hammerit » Wed Feb 05, 2014 4:38 pm

Hares wrote:@lcl
If the player is jumping use the code you already use.
If the player is not jumping use

Code: Select all
hero.y=hero.yprevious

That's a really good idea. :) Thank you.

New question.
Do i need to write collision event for each monster and platform in the game individually?
How i can copy all collisions to a new monster or tile with little code change?
Or that's what programmers-gamemakers do: righting and copying same code for each collision in the game and then changing a little? :D

Curse my perfection and lazynes.
Hammerit
 
Posts: 12
Joined: Sun Feb 02, 2014 9:52 pm
Score: 2 Give a positive score

Re: Precise collision and other question.

Postby Hares » Wed Feb 05, 2014 7:10 pm

Hammerit wrote:Do i need to write collision event for each monster and platform in the game individually?
How i can copy all collisions to a new monster or tile with little code change?

For monsters you can set up one monster, that you don't use in the game but you keep it off screen somewhere.
This monster will have all the code that is identical for all other monsters.
Then when you create a new monster, on the actor panel you can set "inherits events from:" the original off screen monster.
In the new monster you can then code all the events that are different for this new monster.

For the tiles the same method could also work. But then you will have to change the code you are using now.
Now the code is on the hero. So when he collides with the ground it is the hero actor that controls the code.
If you would change it and put the code on the collision events of the ground actor (the one with the tiles), the you could have an off screen tile actor have all the collision codes. And then you could have the other tile actors inherit this.
In the physical response you replace "event actor only" by "colliding actor only".

Keep in mind that you will possibly want different collision events when the platforms are moving.

Hammerit wrote:Or that's what programmers-gamemakers do: writing and copying same code for each collision in the game and then changing a little?

That is also possible. But it is more work, and when you want to change the code afterwards you will need to change it in all the copies too.

Hammerit wrote:Curse my perfection and lazynes.

Bless your perfection and lazynes :D
User avatar
Hares
 
Posts: 105
Joined: Fri Dec 20, 2013 8:39 pm
Location: Belgium
Score: 14 Give a positive score

Re: Precise collision and other question.

Postby Hammerit » Thu Feb 06, 2014 11:19 am

Hares , thank you for all your help and time.
I will posting tutorial soon on how to make jump and perfect collision using PhysicalResponse action. I found solution to all problems and made one minor problem...
Hammerit
 
Posts: 12
Joined: Sun Feb 02, 2014 9:52 pm
Score: 2 Give a positive score


Return to Game Development

Who is online

Users browsing this forum: No registered users and 1 guest