0 votes

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():
            rotate_x(deg2rad(-45))
        elif not topRayCast.is_colliding():
            rotate_x(deg2rad(45))
        elif not rightRayCast.is_colliding():
            rotate_z(deg2rad(45))
        elif not leftRayCast.is_colliding():
            rotate_z(deg2rad(-45))

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

Godot version 3.3.4
in Engine by (12 points)

1 Answer

0 votes

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)
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.