• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

bounec after collision

A

ajater

Guest
I am looking for a away to make the player bounce and return back a little bit when he collide with wall, I tried using the bounce function but it make the player flip after collision with the wall,

any help will be appreciated.
 

jo-thijs

Member
Could you please be more specific?

How is your object moving?
How should he bounce? Completely elastic without rotation?
What do you mean with "the bounce function makes the player flip"?
 
J

Jaqueta

Guest
My best guess is that your image_xscale changes according to the hspeed, OR, the sprite rotates according to the direction that is moving, either way, all you have to do is remove that piece of code.

If you want to make the object lose speed after bouncing, all you have to do is put this alongside the bouncing script:

Code:
speed*=DAMPING_VALUE //Can be between 0 and 1, 0 will completely stop the object, and 1 will not change the speed at all.
 
A

ajater

Guest
Could you please be more specific?

How is your object moving?
the object moving is a car,

How should he bounce? Completely elastic without rotation?
if the car hit the wall from any side it should just return back without rotation,

What do you mean with "the bounce function makes the player flip"?
when I hit the wall the car or the player flip horizontally
 

jo-thijs

Member
Can you give the object information of the car object?

The code that flips the car horizontally lies somewhere else.
 

jo-thijs

Member
When editing an object, there is a button with "Object information" on it.
If you click on it, you get a new window with text in it.
This is the object information.
Copy paste it here.
 
A

ajater

Guest
When editing an object, there is a button with "Object information" on it.
If you click on it, you get a new window with text in it.
This is the object information.
Copy paste it here.

Information about object: obj_car
Sprite: sprite5
Solid: false
Visible: true
Depth: -100
Persistent: false
Parent:
Children:
Mask:
No Physics Object
Create Event:
execute code:

global.sp_max = 10;

hp = 100;

global.sp_gain = 0.3;

global.handling = 5;

image_speed = 0;

friction = 0.05;
 

jo-thijs

Member
That object information is incomplete.
Please, select the entire text (Ctrl + A) first before copy pasting it.
 

jo-thijs

Member
Although, I actually probably don't need the other code.
You're probably setting image_angle to direction every step.
When you counce off a wall, you change direction, so your image_angle would change as well.
If you line things up correctly, it can result in looking flipped (while its actually rotated 180 degrees).

You should control direction and image_angle seperately.
That, or you use negative speeds.
 
A

ajater

Guest
I solve it, I used this code at the collision event:

if (direction == 0){direction = 90}
else if(direction == 90){direction =270}
else if(direction ==180){direction = 0}
else {direction =180}
 

jo-thijs

Member
I'm glad to hear it got solved!

It could be handy for other people though if you also mentioned how you solved it.
Also, if you haven't done so already, mark this topic as solved.
 
Top