# horizontal equivilent to vector.y example?

Get help using Construct 2

### » Mon Jan 14, 2013 11:55 pm

Hello All,

In the platform example tutorial, there is a section that goes over the behavior when jumping on an enemy. In order to create the effect, when we land on an enemy we test to see if our Y value puts us higher than the enemy, and if so we set Vector Y to -700 this gives us the effect of bouncing off of it.

I am working on a similar thing but for running into solid objects when moving above a certain speed. For example if the player is running and their speed is above 450, I want to have them bounce back a little bit when they hit a wall, etc... I can't just say Vector X -700 as that will only move them in one direction and I need to account for the direction they are running at the time. My thought it to setup a Right and Left action (similar to the enemy AI behavior in that same tutorial) but have it on the player, when they are running normal set it to right, and when it is mirrored, set it to left. Then when they hit an object I test for Left or Right, then have them bounce back a bit using Vector X +/- 50.

Is there an easier way to do this? I had thought I saw a behavior for this at one point using a "reverse" action? But cannot seem to find it, also if memory servers, it was not for the type of behavior I am looking for.

My end goal is that when the player is going to fast and they run directly into an object they bounce back a little bit and maybe trigger an animation (have them land sitting on their butt for a second for example). Any thoughts?
B
49
S
11
G
10
Posts: 1,833
Reputation: 14,393

### » Tue Jan 15, 2013 12:02 am

I haven't toyed too much with the platform behaviour, but you should just be able to set a variable to be Vector.X every tick. Then when checking for a collision, just check if that variable is < 0 (running left) or variable > 0 (running right).

Also, you could just do..

If collision
Vector.X = - Vector.X

that should bounce the object in the opposite direction at the speed you were going.
B
15
S
5
G
7
Posts: 877
Reputation: 5,650

### » Tue Jan 15, 2013 12:10 am

Thanks for the input! I will try that when I get home, currently here is my method for it:

on the player object I have an instance variable called Action.

When Arrow Right is pressed Action = right
When Arrow Left is pressed Action = left

On Collision with <whatever object I want>
And Player Speed is > 400
If player Action = right then set Player Vector.X 500
Esle set Player Vector.X -500

or something like that. It works but figured I would see if there was something a bit more simple. Not sure how all these checks will affect end game performance.
B
49
S
11
G
10
Posts: 1,833
Reputation: 14,393

### » Tue Jan 15, 2013 12:18 am

Yeah I tried my shorter methods, and they don't work. The collision sets the vectorX to 0, which is kind of obvious ;p

Your method seems more sound though.

They'll not affect game performance by much, if at all.procrastinator2013-01-15 00:19:18
B
15
S
5
G
7
Posts: 877
Reputation: 5,650