# horizontal equivilent to vector.y example?

0 favourites
• 4 posts
From the Asset Store
a full game example, menu system, with the first level and a boss, to create a horizontal shooter
• 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?

• 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.

• 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.

• ## Try Construct 3

Develop games in your browser. Powerful, performant & highly capable.

Construct 3 users don't see these ads
• 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.

• 4 posts