|
This is a test script i'm using to iron out bugs before i adapt it to use as a 'shoot toward mouse cursor' script. Basicly, the script is on a cube (NO rigid body), and whenever the mouse cursor touches another object in the scene, the box is supposed to move toward the mouse cursor because the raycast is pointing to the cursor and the box is moving toward the raycast. HOWEVER, the box moves in a seemingly random direction and NOT toward the mouse cursor (Grrr) Can anyone tell me where i've gone wrong? function Update() { var hit : RaycastHit; if(Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), hit)) { transform.Translate((hit.point) * Time.deltaTime); } Thank you, Tom :)
(comments are locked)
|
|
Transform.Translate needs a direction and not a location. So I guess this would do it: That did it, AND i learned somthing :) Thanks man, yoo rool! Tom :)
Jul 19 '12 at 12:40 PM
Tea_Doogun
Space.World? ;)
Jul 19 '12 at 01:34 PM
Bunny83
Good point. @Tea_Doogun - you should pass Space.World to Translate as if the object were parented it would probably not be moving in the right direction.
Jul 19 '12 at 01:49 PM
whydoidoit
@whydoidoit: It doesn't actually need to be parented. Rotated is enough ;) Translate, with the default parameter Space.Self, will translate along the objects local axis. Since the direction you pass is in worldspace it won't be moving the right way, unless the object isn't rotated.
Jul 19 '12 at 10:01 PM
Bunny83
Ah yes - serves me right for commenting on a function I don't use :S
Jul 19 '12 at 10:17 PM
whydoidoit
(comments are locked)
|
