hi!,i try to do a mouseclick walking for my pg,now two question…
i use Camera.ViewportPointToRay?
ok if yes,when i have found my point in 3d space,how can i say to my pg,go in that point?raycast?
what is the script or command i study for that? tnx!
hi!,i try to do a mouseclick walking for my pg,now two question…
i use Camera.ViewportPointToRay?
ok if yes,when i have found my point in 3d space,how can i say to my pg,go in that point?raycast?
what is the script or command i study for that? tnx!
anyone? ok,what command for mousex or mousey position?
for this…
var ray = camera.ViewportPointToRay (Vector3(MouseX,MouseY,0));
look for MouseX and MouseY…what is the right command please…
tnx,i found this…
Input.GetAxis (“Mouse X”);
is right?
this was a bit confusing for me. there an example of how to get the mouse positions and the screentoray function there.
TNX!!!only you respond me tnx very much!!! ![]()
ok i try this today,but for me when i click the button,generate a particle in 2d!i want transform the position of my click in 3d space…are complex i know…but tnx!
ok now i have my ray in space and if i click and found a collider he said me hit!and create a primitive,but the primitive i create at center of space,how can i say,create my Cube in the impact point of the ray?
this is the code…
var waypoint2 : GameObject;
function Update () {
if (Input.GetButtonDown(“Fire1”)){
var ray = camera.main.ScreenPointToRay (Input.mousePosition);
}
if (Physics.Raycast (ray, 1000)) {
print (“Hit something”);
waypoint2 = GameObject.CreatePrimitive(PrimitiveType.Cube);
}
Debug.DrawRay (ray.origin, ray.direction * 10, Color.yellow);
}
i have solved,but now,when my player arrive at hit point,continue along the way…where is the error? please respond me…i love this community,but not response…please help me… ![]()
this is the code…
var speed : float;
function Update () {
if (Input.GetButtonDown("Fire1")){
var ray = camera.main.ScreenPointToRay (Input.mousePosition);
var hit : RaycastHit;
if (Physics.Raycast (ray, hit,1000)) {
var target : Vector3 = hit.point;
var moveDirection : Vector3 = target - gameObject.Find("Personaggio").transform.position;
var velocity = gameObject.Find("Personaggio").rigidbody.velocity;
if(moveDirection.magnitude < 1.0){
velocity = Vector3.zero;
}
else{
velocity = moveDirection.normalized * speed;
gameObject.Find("Personaggio").rigidbody.velocity = velocity;
}
}
}
Debug.DrawRay (ray.origin, ray.direction * 10, Color.yellow);
}