Quantcast
Channel: Questions in topic: "addforce"
Viewing all articles
Browse latest Browse all 1264

When to use OnCollisionEnter and OnTriggerStay and how to use rigidbody.AddForce

$
0
0
Hi Sorry for the long question title. I am trying to make a treadmill for a uni project. I want the treadmill/conveyor belt to move the player along its path and if the player tries to move with it they will speed up and against it they will slow down. I have begun researching how to create this effect and I am having trouble and would like some help. I have found this previous question http://answers.unity3d.com/questions/529178/conveyor-belt-physics.html and further research has lead me to something called rigidbody.AddForce. The AddForce sounds very ideal for what I am trying to achieve but my player (which is just a cube for now) just sits on top of my bigger cube (with the belt script attached to it) and moves when I was WASD as expected. Even when I make my player Kinematic and go inside the belt and trigger my "touched" message to activate my player only moves when I press buttons and is not moving as intended. If anyone can shed some light and help me achieve my results and help me understand why my attempts are failing, it would be a massive help. Thank you and here is my script... using UnityEngine; using System.Collections; public class conveyorBelt : MonoBehaviour { private Transform conveyorBelts; private float beltSpeed; // Use this for initialization void Start () { conveyorBelts = transform; beltSpeed = 6.0f; } // Update is called once per frame void Update () { } void OnTriggerStay( Collider other ) { print ("Touched"); other.rigidbody.AddForce(Vector3.left * Time.deltaTime * beltSpeed); } /*void OnTriggerEnter(Collider collider) { collider.rigidbody.AddForce(Vector3.left * Time.deltaTime * beltSpeed); print ("Touched"); }*/ }

Viewing all articles
Browse latest Browse all 1264

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>