hai , i'm new to game development and i consider it as my hobby

``````var velocity = -transform.basis.z * speed * delta     # this is my velocity
move_and_slide(velocity)
``````

and i added 5 rayCat in front , right , left , up , bottom and i want to rotate it like in this code .

``````if frontRayCast.is_colliding():
#print("Got")
bottomRayCast.enabled = true
topRayCast.enabled = true
rightRayCast.enabled = true
leftRayCast.enabled = true
if not bottomRayCast.is_colliding():
elif not topRayCast.is_colliding():
elif not rightRayCast.is_colliding():
elif not leftRayCast.is_colliding():
``````

but it's rotating weirdly in both left and right sides

Godot version 3.3.4
in Engine

It's a fun hobby, isn't it? :)

Trivial point first: if you're getting into game dev then I'd encourage you to leave degrees behind and move to radians. Degrees are cost for no gain and radians come naturally from the geometry. PI radians is 180 so rather than 45 degrees, try to get into the habit of using PI/4. No big deal though.

I assume all the code is in your `_physics_process` method. Yeah, that's going to produce some very erratic behaviour. It'll only rotate when the front one is colliding. PI/4 radians at 60fps is 7.5 rotations per second. Plus the rotations stack. You might get dizzy! :)

Also, you're rotating the object on multiple axes. You have to be really careful about Euler rotations, they're a bit like Rubik's Cubes, once you do them they can be very hard to undo and your result is going to be chaotic. Here's a great piece about the pitfalls that I'd encourage you to read:

https://docs.godotengine.org/en/stable/tutorials/3d/using_transforms.html

Can I ask what you're trying to achieve here? Are you looking for the object to turn towards / away from the collision? If so then the dot product is likely what you need.

by (2,156 points)