0 votes

I have a RigidBody with a camera and a meshinstance as a child,
it rotates whenever i press a button.

when i rotate it it seems to work fine however after i rotate too much the physics engine just seems to stop.

heres my code(in C#):

using Godot; 
using System;

public class SpaceShip : RigidBody
{
Vector3 velocity = new Vector3();

float rotationX = 0;
float rotationY = 0;
float rotationZ = 0;
public override void _Ready()
{

}

// Called every frame. 'delta' is the elapsed time since the previous frame.
public override void _IntegrateForces(PhysicsDirectBodyState state)
{
    if(Input.IsActionPressed("movement_upward"))
    {
        velocity.y = 1;
    }
    else if(Input.IsActionPressed("movement_downward"))
    {
        velocity.y = -1;
    }
    else
    {
        velocity.y = 0;
    }

    if(Input.IsActionPressed("movement_backward"))
    {
        rotationX += 1;
    }
    else if(Input.IsActionPressed("movement_forward"))
    {
        rotationX += -1;
    }

    if(Input.IsActionPressed("movement_left"))
    {
        rotationY += 1;
    }
    else if(Input.IsActionPressed("movement_right"))
    {
        rotationY += -1;
    }


    RotateX(Mathf.Deg2Rad(rotationX));
    RotateY(Mathf.Deg2Rad(rotationY));
    state.ApplyCentralImpulse(velocity / 4);
}

}

is this a bug or am i doing something wrong?

asked May 11 in Engine by ComLarsic (30 points)

i can not see an error , but in my case when godot freeze is because an infinite loop in the code.. check all the code just in case is that.

Please log in or register to answer this question.

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 How to use this Q&A? before posting your first questions.