Topic was automatically imported from the old Question2Answer platform.
Asked By
jbko6
Hi there!
I’m trying to implement a system that knocks the player back when you fire a gun. I’ve been trying to use $Head.rotation_degrees, but that only outputs one axis. When I print it, it outputs something like (-0, 138.78, 0) instead of 3 numbers.
By the looks of your code, $Head must some sort of a Spatial (3D) object. In that case $Head.rotation_degrees returns a Vector3 object. So, a 3D vector. In fact, you’re treating it as such when you reference the x, y, and z components of your aim variable.
Since aim, knockback, and velocity all appear to be Vector3 objects, you can perform much of the math directly on the vectors themselves rather than their individual components.
For instance, you can replace those last 3 lines with velocity += knockback
I’m not exactly sure what you’re looking for, but maybe check out the Vector Math topic for a basic vector overview?
(-0, 138.78, 0) is three numbers. If you’re trying to move the player backwards use global_transform.basis.xform(Vector3.BACK * knockback) in a method like move_and_slide(), knockback in this case would be a float.