Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by FakedMeerkat · Jun 28, 2014 at 05:40 PM · c#playercharactercontroller

Third person movement similar to Max Payne

Hey everyone!

So basically, I am having a bit of trouble getting the movement in my game to work the way I want it. I am trying to create a basic game with movement similar to Max Payne for a side project. The game is similar to Max Payne in that you can walk forwards in the direction the camera is pointing, but you can also walk forwards while aiming left or right, by holding the A or D key to move relative to the rotation of the camera, so it is sort of like strafing, but a bit different.

I hope this makes some sense, but here are some screenshots of the kind of behavior I'm looking for:

alt text

This is an example of walking forwards.

alt text

And here is an example of walking forwards, whilst aiming in a different direction.

In the case of the second image, I would be holding the A key (or left arrow or whatever it is bound to) so that I am moving to the left of the screen, but I would be aiming to the right of my character, even though that is the center of the screen.

At the moment I am always moving in relation to world space, so that is how I can capture these screenshots, but I have attempted to use transform.TransformDirection to get the desired result, and I can move forward, backward, left and right, except I cannot aim in a different direction, as my entire player character rotates if I move the mouse.

NOTE: I am using C# for scripting.

I am still fairly new to C#, but I should be able to handle most concepts, as I have experience in a few other programming languages, including C++.

I hope this is enough information, and absolutely any help would be greatly appreciated!

Thanks,

Evan.

maxpayne01.png (99.9 kB)
maxpayne02.png (93.3 kB)
Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image KMKxJOEY1 · Jul 01, 2014 at 01:49 AM 0
Share

If all you want to do is rotate the lower half of the body, make a script with a Transform variable that holds the lower body parent transform. Then grab the motion component (whatever motion input script you're using) and therefore the vector that the player is moving along. After that it's just a simple Quaternion.LookRotation

avatar image FakedMeerkat · Jul 01, 2014 at 02:05 AM 0
Share

Hey $$anonymous$$$$anonymous$$$$anonymous$$xJOEY1, thanks for your comment man!

So, I ended up using a simple transform.LookAt method I found elsewhere that only rotates on the y-axis, which works pretty well. The only real problem I have left is that I want to make the player only rotate when he is moving, because with my current method he rotates if I look around when idle.

For the rotation now, I have made a really newbie "if" statement that checks if Input.GetAxis("Horizontal") is greater than or less than 0.1, and the same for the Vertical axis and then calls the transform.LookAt. I'm not sure why, but the character still rotates even when stationary.

I think I may be messing up the less than and greater than signs and somehow making it only rotate between -0.1 and 0.1 or something, I don't know :P

Here's an example:

     float v = Input.GetAxis("Vertical");
     float h = Input.GetAxis("Horizontal");
 
 
     if (v > 0.3 || v < 0.3 || h > 0.3 || h < 0.3) {
         transform.LookAt(targetPosition);
     }

I'm using FinalI$$anonymous$$ for the ai$$anonymous$$g of the gun, so that is how I basically move the upper-half of the character without the lower half, and it is working great.

Thanks again for your comment!

[Edit]

I can't believe I missed the negative signs!

I fixed that now, and it works great!

Is there a better method than this dodgy if statement?

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by FakedMeerkat · Jul 01, 2014 at 01:05 AM

I made a bit of progress by adapting the Third Person Input script from the new sample assets, and it lets me move in the desired fashion, but I cannot figure out how to rotate my player's lower body to face forwards when moving forwards.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Multiple Cars not working 1 Answer

Loading a new level from a previous one. 1 Answer

Make player not be seen by AI, when player in foilage and shadows. 1 Answer

Starting out C# help 2 Answers

C# Character Controller Collision If Statement 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges