How to make a bouncer

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By godotuser123

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.
In c# please

thx for the helpers

:bust_in_silhouette: Reply From: Pomelo

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.

but assuming the bouncer is pointing to the left
in order to do as you say I’ll have to modify each bouncer manually
I think it amateurish…

godotuser123 | 2022-06-11 18:12

You can use the bouncer’s Y axis for the direction, multiplied by some scalar for amplitude. You can then add the resulting vector to the character’s existing motion vector.

stormreaver | 2022-06-11 23:30

You have a huge amount of different ways to do it. But in all of those, the info of where the bouncer is “pointing to” has to exist somewhere.

For example, if you have only one bouncer scene that you then rotate when you put it in the world, you can go to the scene and add a “pointer” Node2d as a child in the apropiate position, and then you just say that the direction is equal to the pointer position normalised.

Another example, instead of rotating them, you could have an export var that says “right”, “left”, etc… and then the var direction checks this and takes the apropiate value (and also rotates the sprite acordingly).

Somewhere in the procces you have to tell the engine where the bouncer is pointing at, wether visually or in code.

It seems you are not really puting in the effort of trying to figure it out

Pomelo | 2022-06-12 15:25

with all due respect
you can’t judge my efforts through a computer
if u wanna help , then help with no unnecessary comments

godotuser123 | 2022-06-12 18:49

Sorry, not refering to your actuall effort in making the game, but with how you were dealing with the awnser. Let me know if you need more help.

Pomelo | 2022-06-12 18:55

Sorry but couldn’t figure it out yet

godotuser123 | 2022-06-12 19:07

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

godotuser123 | 2022-06-12 19:29

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.

stormreaver | 2022-06-12 22:26

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

func _ready():
    direction = ($Pointer.global_position - global_position).normalized()

func _on_player_detected():
    emit_signal("player_detected", direction)

Of course how you pass the direction to the player is up to you, I just would do it like this

Pomelo | 2022-06-12 23:29

If Im using a staticbody?

godotuser123 | 2022-06-13 04:24

It’s the same if you’re using a StaticBody.

stormreaver | 2022-06-13 11:16