1. Hello,

    I am trying to spawn a player entity and adding gravity to it but i can't get it working, my entity is just flying...

    Code:
                var newPlayer = GameManager.server.CreateEntity("assets/prefabs/player/player.prefab", info.spawnInfo.position, info.spawnInfo.rotation).ToPlayer();
                Rigidbody rigidbody = newPlayer.gameObject.GetComponent<Rigidbody>();
                rigidbody.useGravity = true;
                rigidbody.collisionDetectionMode = CollisionDetectionMode.ContinuousDynamic;
                rigidbody.interpolation = RigidbodyInterpolation.Interpolate;
                rigidbody.velocity = newPlayer.transform.position;
                Vector3 vector3 = Vector3Ex.Range(-1f, 1f);
                rigidbody.angularVelocity = vector3.normalized*1f;
                rigidbody.isKinematic = true;
    
    Anyone know ? Maybe @Wulf ? @Nogrod ?
     
  2. No one?
     
  3. Wulf

    Wulf Community Admin

    I tried messing with player gravity before, but haven't done so it months.
     
  4. Have you something that can help me ?
    Because i just try to take a look on every OnKilled hook and both use RigidBody, but it seem it simply ignore my usegravity = true.
    I tested with a crate and it work but not with a player entity user player.prefab
     
  5. rigidybody.isKinematic = true;
    This line is making it so that your rigidbody will not react to physics.

    rigidbody.velocity = newPlayer.transform.position;
    This line is setting their velocity to their position.... which will make them travel very quickly in a random direciton based on their position in the server.

    Unity does 3d Rigidbody gravity based on a global constant: Physics.gravity see Unity - Scripting API: Physics
    Who knows if Facepunch uses that constant though...

    If you want to do gravity per rigidbody you will need to be using rigidbody.AddForce() in the FixedUpdate() loop.