- Home /
Collisions not working when player stands still
Hey Guys, been trying to figure out this problem for a while and its become way to confusing for my newly developed JavaScript brain to handle. Ok so my game is a 2.5D platformer where the player collects "Burgers" for health and is then hurt by salads, he also grows fatter and skinnier as he eats the burgers.
When the "player" collides with burgers the burger variable increases by one and everything is fine, when the player run into the enemy everything is fine, UNTIL the player stands still and let the enemy collide with the player, then NOTHING happens to the variables.
//heres my code:------------------------------------------
var BurgerPositive : int = 1; var BurgerNegative : int = -1;
function Start(){ BurgersGui.Burgers = 1; }
function Update(){ //bellow is code that states, if you loose all the burgers, it executes the code if(BurgersGui.Burgers <1){ Application.LoadLevel(0); } }
function OnTriggerEnter(collision : Collider){ if(collision.gameObject.tag == ("Collectable")){
//Applies the health by sending the information to the BurgerGui.js.
BurgersGui.Burgers +=BurgerPositive;
//plays audio clip assigned to this object
audio.Play();
//Makes the player get fatter
transform.localScale += Vector3(0.1,0.1,0.1);
}
//Below is script that causes damage and reduces one variable
if(collision.gameObject.tag == ("enemy")){
//Applies the damage by sending the data to the HeartsGui.js.
BurgersGui.Burgers +=BurgerNegative;
transform.localScale += Vector3(-0.1,-0.1,-0.1);
}
}
Does anyone know what the problem might be?
PS: Also look at this Question as it looks like it is about the same problem you have: http://answers.unity3d.com/questions/39169/ontriggerenter-only-works-if-gameobject-is-moving.html
I converted my comment to an answer so that you can accept it to mark the queston as solved. Good luck with your project :)
Answer by ExTheSea · Apr 28, 2013 at 02:47 PM
I'm guessing OnTriggerEnter won't get triggered if the player stands still because he is not actually entering a collider. I would suggest you to try adding a OnTriggerEnter function to the Enemies and then call a function on the player if he collides with the Enemy.
Your answer
Follow this Question
Related Questions
Enemy AI With changing Player 0 Answers
Checking name from hit from Raycast in array 2 Answers
Setting Scroll View Width GUILayout 1 Answer
Can someone help me fix my Javascript for Flickering Light? 6 Answers
How to update scoreline on a HIT? 1 Answer