0
votes

I am new to Unity trying to make my first game (a Third Person Shooter). It's been now more than a week that I've tried again and again to get my character moving using a rigidbody component and NOT the Character Controller or the simple transform.Translate.

I have had about 30 web pages opened since a week browsing topics about it but I haven't found anything (almost made me feel like I am trying to do something impossible lol...).

So, I want to move my character just like in Splinter Cell Blacklist, and to have the camera with the crosshair controlled by the mouse (if I shoot, the character would rotate if not facing the target and then shoot).

For the movement, if it is not possible with the rigidbody then I'll use one of the others, it's just that I love the real feeling that the rigidbody has.

If there's even a tutorial that break it down to really understand, that would be great or just some code with comments (I have a C# background).

float moveSpeed = 6f;            // Player's speed when walking.
float rotationSpeed = 6f;
float jumpHeight = 10f;         // How high Player jumps

Vector3 moveDirection;

Rigidbody rb;

// Using the Awake function to set the references
void Awake()
{
    rb = GetComponent<Rigidbody>();
}

void FixedUpdate()
{
    Move();
}

void Move ()
{
    float hAxis = Input.GetAxis("Horizontal");
    float vAxis = Input.GetAxis("Vertical");

    Vector3 movement = new Vector3(hAxis, 0f, vAxis);
    rb.position += movement * moveSpeed * Time.deltaTime;
}
1
I mainly do 2d Unity work so I dont know how much help I can be with your situation, but here is a really interesting video I found that I think will be able to help you out a bit. Dont let yourself get down about it, its always hard at the start. I found that the longer I kept working at it not only did it get easier but it got way more fun!Jessy Doyle
"tried to get my character moving using a rigidbody component and NOT the Character Controller". Why?Fattie
minor, note that you rarely if ever use "FixedUpdate" in Unity. forget about it.Fattie
@JessyDoyle Thanks for your reply and yes I have watched a lot of his videos, he's really good! And it's actually because of that specific video that I want to go with a rigidbody ahah.. I'll dig a little moreManu
@JoeBlow Why, because it has a way different feeling for the end result I want, and just like on the video linked by Jessy Doyle, it explains what I have just said. And from what I have read on Unity website, when you want to use physics in Unity, you rather want to do that in the FixedUpdate, and since for what I know so far, it's Unity that says so, I figured it's the right way.Manu

1 Answers

2
votes

My idea. If you want the real feel, you need the rigidbody.addforce to your character at the proper part of the character body. Not the rigidbody.position.

Hope help.