- Home /
Question by
davit_goder · Aug 31, 2016 at 05:38 AM ·
movementphysicsmovement script
isKinematic does not always work
hello, I have the following problem: I want an object to skit at ground, so I do
GetComponent<Rigidbody>().isKinematic = true;
BUT SOME OF THE OBJECTS CONTINUE TO MOVE ANYWAY. what am I messing?
full code is here as well
using UnityEngine;
using System.Collections;
public class rand_movm : MonoBehaviour
{
//
public GameObject go;
//
public float timer;
public int newtarget;
public float speed;
public NavMeshAgent nav;
public Vector3 target;
void Start()
{
nav = gameObject.GetComponent<NavMeshAgent>();
}
void Update()
{
//
float dist = Vector3.Distance(go.transform.position, transform.position);
if (dist < 6)
{
GetComponent<rand_movm>().enabled = false;
// transform.position = new Vector3(go.transform.position.x, go.transform.position.y, go.transform.position.z);
gameObject.transform.position = new Vector3(1, 5, 1);
GetComponent<Rigidbody>().isKinematic = true;
}
else
{
timer += Time.deltaTime;
if (timer >= newtarget)
{
newtarget1();
}
timer = 0;
}
}
void newtarget1()
{
float myx = gameObject.transform.position.x;
float myz = gameObject.transform.position.z;
float xpos = myx + Random.Range(myx - 100, myx + 100);
float zpos = myz + Random.Range(myz - 100, myz + 100);
target = new Vector3(xpos, gameObject.transform.position.y, zpos);
nav.SetDestination(target);
}
}
Blockquote Thanks!
Comment
Didn't checked your code but simply you can use rigidbody constraints to freeze them,or try Rigidbody's Sleep & WakeUp function.
Your answer
Follow this Question
Related Questions
Quake Movement in Unity 1 Answer
How Time.deltaTime affects movement ? 4 Answers
My player's movement is slippery 1 Answer
Jump only sometimes works and player doesn't always jump high? 1 Answer
Non slippery movement 1 Answer