0 votes

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

in Engine by (36 points)

1 Answer

0 votes

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)

what about the axis?
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

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

If Im using a staticbody?

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

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.