Muku
May 5, 2014, 4:23pm
1
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.
#pragma strict
function Update () {
transform.Translate(Time.deltaTime * 5, 0, 0);
}
Simple code as you can see. It’s just attached to the character.
Muku:
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.
#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.
Muku
May 5, 2014, 5:56pm
3
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
void OnCollisionEnter(Collision collision)
{
// your code, i.e. check for a tag and then do something
}
Muku
May 5, 2014, 7:08pm
5
#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.
Muku:
#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:
function OnCollisionEnter(collision : Collision)
{
// insert your code here
}
Muku
May 5, 2014, 7:27pm
7
No errors this time but for some reason it cancels the autorun feature. Reverts back to using WASD.
#pragma strict
function OnCollisionEnter(collison : Collision){
transform.Translate(Time.deltaTime * 5, 0, 0);
}
Muku:
No errors this time but for some reason it cancels the autorun feature. Reverts back to using WASD.
#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.