Hello
I am quite new to Unity3d
I want to code an RPG movement
I mean ,my player should follow the mouse pointer regardless of the camera position and angle as well as of the terrain height
Might you just suggest a list of class \ methods whic can be of use (RayTrace() …etc
Thanks in advance
nobody ?
Can anybody confirm that it is possible to achieve this type of player controller
I mean that it is possible just using the standard class \ methods supplied with Unity
I will find the way by myself , going through the manual
Thanks in advance
Hi Alberto, my search-foo isn’t working at the moment as I try to figure out why my NSString object isn’t nicely converting to an int_64t, but there have been a couple of discussion about RPG movement on these forums in the past. Someone will come along shortly I’m sure to point you in the right direction.
What exactly are you looking for?
?
If you need navigation around buildings and other obstacles, I have a pathfinding solution available at AngryAnt.com.
I left click on the screen and my player must turn and move to that direction
In other words, given :
The mouse 2d screen coords , the camera 3d coords and the camera yaw,tilt and roll angles
I want to find the related terrain 3d world coords
Use the two links I provided - the first can be used to give you the mouse position in the context of the camera transform and the second has the physics engine raycast from that point in a given direction (camera.transform.forward would make sense) in order to get the intersection point between this line and the terrain (or which ever other collider you might be aiming for).
hello
I tried this:
var hit : RaycastHit ;
function Update () {
var ray = Camera.main.ScreenPointToRay (Input.mousePosition);
Physics.Raycast(Camera.main.transform.position,ray.direction,hit,100);
print(hit.point[0]);
}
The Raycast() function return true
I would expect that the structure “hit” update its values , moving the mouse over the screen, but print() return a constant value
Same using the function suggested by angryAnt
What am I doing wrong ?
Thanks in advance
I took your code, change:
print(hit.point[0]);
to:
print(hit.point);
And it tells me the x, y, z position no problem. (the way you had it it would only say the x position)
I think the problem you’re having is you need to point your mouse at a object with a collider attached. If you just point your mouse at empty space it can’t give you a position since it doesn’t no the depth to go to.
The other possible problem is distance the ray goes is too low, in which case change:
Physics.Raycast(Camera.main.transform.position,ray.direction,hit,100);
to:
Physics.Raycast(Camera.main.transform.position,ray.direction,hit,10000);
Oops…you are right, thanks
Vector hit.point returns exactly the 3d coords of the terrain pointed by the mouse
Just from time to time the updating of the coords stops and it starts again after clicking on the screen
This happen when the mouse touches a GameObject on the terrain , but I did not use the "layer mask "
" the way you had it it would only say the x position "
It is what I expected but it returns a constant not a variable coord ( moving the mouse )