Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
0
Question by Pyrem · Jul 07, 2018 at 07:56 PM · rigidbodycontrollermovement scriptjoystickcharacter controller

I can't seem to get this movement + automatic lookat the direction of movement work for a 2.5D game

Good Day!

I need help making this script.

1) Movement (which works currently) 2) Rotation (LookAt) as per the movement direction automatically 3) Use animations attached to the character.

After looking here and there, could not find how to create this specific script for these sets of requirements.

Please help!

GitHub Link

Thanks.

 using CnControls;
 using UnityEngine;
 
 public class PlayerController : MonoBehaviour
 {
 
     [SerializeField] private float defaultSpeed = 5f;
     [SerializeField] private float infectedSpeed = 7f;
     [SerializeField] private float humanSpeed1 = 6f;
     [SerializeField] private float humanSpeed2 = 7f;
     [SerializeField] private float humanSpeed3 = 8f;
     [SerializeField] private float sensitivity = 4f;
 
     private PlayerMotor motor;
     private Vector3 _movVelocity = Vector3.zero;
     private Rigidbody rb;
 
 
     // Use this for initialization
     private void Start()
     {
         rb = GetComponent<Rigidbody>();
     }
 
     private void FixedUpdate()
     {
         PerformMovement();
     }
 
     private void Update()
     {
 
         CharacterController controller = GetComponent<CharacterController>();
 
         // Axis are inverted due to orientation
         // Define the axis as per the joystick input
         var _xMov = CnInputManager.GetAxis("Vertical");
         var _zMov = CnInputManager.GetAxis("Horizontal");
 
         // Debug.Log("X = " + _xMov + " || " + "Z = " + _zMov);
         
         // Set position values as per the joystick input
         var _movHorizontal = transform.forward * _xMov;
         var _movVertical = transform.right * _zMov;
 
 
         // Sets speed as per the tag
         defaultSpeed = tag.Contains("Zombi") ? infectedSpeed : humanSpeed1;
         
         // Sets current speed
         var _velocity = (_movHorizontal + _movVertical).normalized * defaultSpeed;
        
         // Moves the character using the velocity set
         Move(_velocity);
     }
 
     private void Move(Vector3 _velocity)
     {
         // Set the zero velocity to the active velocity
         _movVelocity = _velocity;
     }
 
     private void PerformMovement()
     {
         // Move when the velocity is not zero as per the PlayerController
         if (_movVelocity != Vector3.zero)
             rb.MovePosition(rb.position + _movVelocity * Time.fixedDeltaTime);
     }
 }

Comment
Add comment
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

0 Replies

· Add your reply
  • Sort: 

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

181 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

I need to control my player using a joystick. I used the default joystick script in Unity, but i am not able to integrate it with the player. Please help. I am attaching the player script, its currently using keyboard input 0 Answers

Using mobiles as joysticks to control my game running on computer 0 Answers

Slow falling speed on player (with RB), but all other objects are fine (checked scaling). 0 Answers

Rigidbody velocity in direction facing 2 Answers

How do I get a character to walk on walls and ceilings? 1 Answer


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