Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | DoubleCakes | |
Old Version | Published before Godot 3 was released. |
You can convert a Vector2 into radials using the .angle() function, but can you do something in reverse?
In a game I am making, the player character produces a Sword object when the player attacks. This Sword object’s position and rotation depends on which way the Player object is facing, represented in a normalized Vector2 called face and multiplied by a constant called SWORD_OFFSET so the sword isn’t right in the center of the body but along a perimeter.
set_pos(get_node("../Player").get_global_pos()+(face*SWORD_OFFSET))
What I am trying to do is modify this Sword position code so that it can take the face of the player object, turn it into a radial with .angle() add an additional radial value to modify a bit, and then turn that back into a Vector2 so it can be used with SWORD_OFFSET to determine the position of the sword.
My use of radials is because in another part of code I use a normalized face Vector2 to determine the rotation of the Sword object.
set_rot(face.angle()+(SWORD_ANGLE_OFFSET*get_node("../Player").attack_state))
In this bit of code the Sword takes the attack_state value from the player (basically how far along it is in an attacking animation) to determine its angle in the sword slash, represented in a value of 0.3 radials.
Overall, I could just back up a bit and redo this bit of code so it works with both rotation and positioning but I’m curious if there’s a way to make Vectors out of radials.
Did you mean “Radian”? I am pretty sure you do, but … I could of course be wrong.
Tybobobo | 2016-11-08 21:41