- Home /
Dual stick shooter controls??
Hello, currently i'm making a kind of "dual-stick shooter" which will later resemble boxhead 2 - a popular web-game. I got my character to correctly although the rotation is missing. I move the character with w;a;s;d and want him to rotate and look at where my mouse is on screen.
How can i make the rotation part??
If you have any ideas, scripts or tutorial sugestions please leave them here :)
Have you looked at the "Angry bots" demo in the asset store? I would just rip the control system from that. As far as I know demos made by Unity themselves are free to use in any of your Unity projects.
Answer by chemicalvamp · Oct 13, 2011 at 09:02 PM
Something like this should work in update() or fixedupdate(), You could get fancy and add in smoothing. (I didnt test this, and it MAY rotate your character in undesired angles so it may need tweaking)
RaycastHit hitinfo;
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); // casts a ray from the center of the camer to the mouse pointer
if (Physics.Raycast(ray, out hitinfo)) // stores the collision info of the raycast
{
transform.LookAt(hitinfo.point); // look at the point of space you hit
}