|
Hi guys, I have some pickups in my game, which are supposed to move towards the player after being picked up. Here is GemPickup.js:
The OnTriggerEnter() code works just fine, since the the debug log message gets printed. However, although the fact of getting picked up is being detected in Update(), the gems just never seem to meet the player, preferring to move in bizzare directions instead. What gives? MachCUBED
(comments are locked)
|
|
It's this line if I'm not mistaken: You shouldn't be setting transform.position to the difference here; you should use Translate(). For example, if your player was at 10, 0, 10, and your object was at 15, 0, 15, then your computed value (that you're plugging into transform.position) would be 5, 0, 5. That's why your object is bouncing around everywhere. I tried changing the following: transform.position = transform.position - target.rigidbody.position to: transform.Translate(transform.position - target.rigidbody.position * Time.deltaTime); Not only does it still act funny (in terms of going all over), but now it eventually spits out the following console error: transform.position assign attempt for 'Emerald' is not valid. Input position is { -Infinity, -787959360953950142464.000000, 1426979897156153901056.000000 }. UnityEngine.Transform:Translate(Vector3) GemPickup:Update() (at Assets/Props/Scripts/GemPickup.js:24) Why is it passing -infinity as a value?
Apr 06 '12 at 12:02 AM
MachCUBED
(comments are locked)
|
