I'm this is an easy fix but I can't seem to find any info on it. I got my character to autorun but now he ignores the collision boxes of my static objects. I have an enemy that moves that I'm still able to hit and die from. Code (csharp): #pragma strict function Update () { transform.Translate(Time.deltaTime * 5, 0, 0); } Simple code as you can see. It's just attached to the character.
In order to collide without your static object you will need to add the OnCollisionEnter function here too. Also, don't forget to attach a rigidbody.
I'm just using the character FPS controller script in unity so it has the rigidbody attached to it. What would the OnCollisionEnter look like if i were to add it to this script?
Is it the Rigidbody FPS Walker script from the wiki or one script which comes with unity standard assets? Basically, you'd put the following code Code (csharp): void OnCollisionEnter(Collision collision) { // your code, i.e. check for a tag and then do something }
Code (csharp): #pragma strict function Update(){ transform.Translate(Time.deltaTime * 5, 0, 0); } void OnCollisionEnter(Collision){ } So this is how I entered it becuse if I added it up top as a void the autorun would stop working. Also it gives me an error saying "void" is not a valid macro. The FPS controller I'm using is the one included in the Unity assets.
My bad, you're using Unityscript/Javascript and i posted C#. Try: Code (csharp): function OnCollisionEnter(collision : Collision) { // insert your code here }
No errors this time but for some reason it cancels the autorun feature. Reverts back to using WASD. Code (csharp): #pragma strict function OnCollisionEnter(collison : Collision){ transform.Translate(Time.deltaTime * 5, 0, 0); }
Leave that code in Update(), put your code in OnCollisionEnter that you want to execute when a collision occurs.