0
\$\begingroup\$

I am wanting to make a 3d RPG with unity, and I'm in the planning phase. For the camera I decided to make it GTA style. I want the camera to be rotated around the player without effecting the movement of the player. If anyone can give any pointers on this, I would be very grateful.

\$\endgroup\$
1
  • \$\begingroup\$ Alexandre Vaillancourt, thanks for the edit, I'll keep that in mind next time ;) \$\endgroup\$ Mar 3 '17 at 19:22
1
\$\begingroup\$

This snippet of code should help you.

1.) Attach your main camera to your main character and position it wherever you want it relative to said character.

2.) Attach a script to your camera with the following code somewhere in it, where x, y, and z are the angles you want to rotate the camera:

Camera.main.transform.eulerAngles = new Vector3(x,y,z);

Note: I haven't (and won't be able to until the weekend arrives) tested this personally, this is just from scavenging the docs.

I am not sure what exactly you want you input method to be, but to get input from the keys you call if(Input.GetKeyDown(char key)) DoSomethingWithInput(), so something like this (but again, untested; you'll probably have to tinker with values and such to get it to behave how you want.);

if(Input.GetKeyDown('d'))
{
    Camera main = Camera.main;
    main.transform.eulerAngles += new Vector3(1 * xWalkingVelocity, 0, 5 * zWalkingVelocity); //Where xWalkingVelocity is either the xVelocity of the character OR 1 if the character is not moving. Same for zWalkingVelocity.
}
\$\endgroup\$
4
  • \$\begingroup\$ I know you're going to hate me for this. I know that I don't want the camera to move forward/backward, I want the camera to be able a full 360 around the character. What would I put in the y/z parameter. (Yes i'm a noob at Unity 😂) \$\endgroup\$ Mar 3 '17 at 19:19
  • \$\begingroup\$ @BramwellSimpson Do you want it to move a full 360 in any direction, or just the x and y axis? y is the amount along the y axis you want to rotate (that is, up and down), z is the amount along the z axis you want to rotate (that is, depth, so it would rotate you around the character). Presumably you would obtain input from the user in some way to determine what y and z should be (in GTA on mobile it is usually dragging the screen, on console it is usually the controllers' thumbsticks, arrows, letters (its been a while since I've played GTA)). \$\endgroup\$ Mar 3 '17 at 19:36
  • \$\begingroup\$ It'll be built for the PC, Mac and Linux so I won't have to worry about controllers and the screen dragging. And yes y and the z axis, to describe it in a different way, Goat Simulator or Skyrim style (I think...) \$\endgroup\$ Mar 3 '17 at 19:53
  • \$\begingroup\$ @BramwellSimpson Okay, sorry, I have been offline for a while. I made some edits to attempt to address your problem better. \$\endgroup\$ Mar 6 '17 at 15:49

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .