Hi, im trying to get the Ori abilities (Bash) to work but im stuck with the rotation.
What i currently have is when the player is near the hook the time slows down and you can rotate the arrow where to go but i cant get my head around how to apply the arrow direction to the player. Any help is appreciated. Thank you in advance.
Trying to make Ori bash abilities.
Toxe To keep it simple i have a Area2D and a Raycast2D after the Area2D register a body (Hook Target) entering the raycast points to the HookTarget with that the player moves towards the HookTarget and when it passes the HookTarget
new_velocity = new_velocity.normalized() * arrivePush
player.velocity = new_velocity
player.move_and_slide()
the player just gets a push in the direction the raycast is pointing. I can post the code but it will complicate it more then it is but if you need more of the code im happy to post it.
What you mean by applying arrow direction to player?
Are you trying to make the player character share the same orientation of the arrow and apply a force x, y proportional to that orientation/angle in 2d?
MagickPanda Yes exactly that.
Galla This can definitely be solved with trig
# Calculate direction vector
var direction = Vector2(cos(rotation), sin(rotation))
new_velocity = new_velocity.normalized() * arrivePush
player.velocity = new_velocity * direction
player.move_and_slide()
- Edited
FreakyGoose It works the way you described but i have another problem. Currently im rotating the arrow
if(Input.is_action_pressed("right")):
head.rotation += 0.05;
if(Input.is_action_pressed("left")):
head.rotation -= 0.05;
print(head.rotation )
its pretty simple and stupid, it rotates the arrow but it never limits the arrow. If i hold left i can go to infinite. Do you know a way to rotate the arrow a better way? You can see the numbers in the gif bellow.
- Edited
- Best Answerset by Galla
Galla
I can already see from your code you will have issues with also using analog inputs since you are not taking into account the Up and Down input. If I remember correctly, Ori allows you to use the analog stick to rotate or quickly snap to any direction you want without waiting for a full rotation to get to the desired direction.
This is a better way to make this work with both arrow buttons and analog stick:
##Remember to register your inputs in InputMap in project settings
var look_direction: Vector2 = Vector2(Input.get_axis("Left", "Right"), Input.get_axis("Up", "Down"))
var look_direction_length = look_direction.length_squared()
##Only record input when analog is pulled halfway
if look_direction_length > 0.5:
var input_look_angle = atan2(look_direction.y, look_direction.x)
head.set_rotation(input_look_angle)
The downside of this method is that you will no longer be able to rotate the arrow by pressing buttons, the arrow will instantly snap to the direction. You can find a way to mix both methods and see what works best for you.
FreakyGoose Thank you, you rock !