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...
Anyone know ? Maybe @Wulf ? @Nogrod ?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;
Gravity of player entity
Discussion in 'Rust Development' started by sami37, Dec 19, 2016.
-
No one?
-
Wulf Community Admin
-
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 -
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.