- Home /
How can I make my coins move without knocking my player around?
I have coins that I'm spawning and making fly from left to right so the player can jump up and collect them. When they collide I just want to destroy the coin and increment the coinCount. The problem is that when the coin hits the player, it knocks him around a little bit. I've already locked all of the axis and rotation I can on the player but I'd like to make the coins have no impact on the player at all. Reducing the coin mass makes them not move across the screen properly. Is there a better way to move the coins or should I be using isKinematic? I read that moving an object without a rigidbody is bad for performance which is why I did it this way.
var objectSpeed : float = 100;
function Start ()
{
}
function Update () {
rigidbody.AddRelativeForce(objectSpeed/100*-1, 0, 0);
}
Answer by Gurc · Apr 05, 2013 at 07:04 PM
I think you should make mass 0, and add velocity, not force like:
And you should do that in start. If you add it in each loop that would be another problem.
(I wrote in c# you should translate it to java.)
function Start ()
{
Vector3 Direction=new Vector3(x,y,z);
Direction.normalize();
Direction*=objectSpeed;
rigidbody.velocity+=Direction;
}
Turning them into triggers didn't make much of a difference, I'm guessing because I was destroying them after the collision anyway so they didn't have time to bounce off of anything. I made them triggers anyway, since I think that's probably more appropriate. $$anonymous$$oving with velocity fixed the issue.
function Start ()
{
rigidbody.velocity = Vector3(-2,0,0);
}
Answer by Dracorat · Apr 05, 2013 at 07:09 PM
You need to turn the coins in to a trigger using the Is Trigger property. This turns off their simulation of bounce and rotation during a collision and moves collision events to the trigger functions instead of collision functions. (But those functions are still only called when the collision occurs.)
http://docs.unity3d.com/Documentation//ScriptReference/Collider-isTrigger.html
http://docs.unity3d.com/Documentation//ScriptReference/Collider.OnTriggerEnter.html
Your answer
Follow this Question
Related Questions
Guidelines for using rigidbody, collider, CharacterControllerScript, etc? 3 Answers
How can i Prevent Kinematic object not to pass through another rigidbody object 1 Answer
Disabling isKinematic on a hinge joint at runtime - keeping motion to axis 0 Answers
Disable ragdoll without changing Kinematic boolean? 2 Answers
Simple Movement Game: Physics vs Manual Collision Detection? 2 Answers