Hello
I'm trying to make a bouncer that will make the player jump relatively to the bouncer's pointing direction(if it points up then the player will go up, if it points to the right the player will jump to the right, like sonic bouncers)
anyway, I thought the best way to do it is by using Raycast2D , but I couldn't find a way to make the player jump to a certain direction.

thx for the helpers

in Engine

Sorry to be that guy, but what do you mean by jump? Assuming you have a movement system, gravity and "friction" (deceleration in the x axis, most of the time) working in your game as most platformes do, you could do what the sonic bouncers do, by just setting the velocity.x or velocity.y to a realy high value when the bouncer triggers (you can handle the trigger with many things, including area_detected methods). And of course, you can have a var or export var in each bouncer saving its direction, which you can send to the player with a signal for example.

by (418 points)

for example if the bouncer is pointing to the northeast direction
what then?

Assuming that the Y axis is up by default (without rotations), then the math is the same all the time. I'm also assuming a KinematicBody2D. When you orient your node, the local Y axis will orient the same way as well. If you rotate your node so it's pointing to the northeast, the locate Y axis will also be pointing northeast.

To impart a bounce to your motion vector:

`vecMotion += bouncer.transform.basis.y * nBounceForce`.

If you're using a RigidBody2D, then you impart the bounce using one of the impulse functions rather than tracking the motion yourself. But the force calculation is the same either way.

Its the same. If you use an "empty" Node2d as the pointer, doesnt matter where the bouncer is pointing, the position of the pointer will always tell you the direction you want to pass to the player. you would do it like this (seudo code)

``````# Bouncer script

signal player_detected(direction)

var direction: Vector2