Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 NarutoU21 · Aug 19, 2021 at 12:27 PM · rigidbodycharactercontrollermovement scriptfollowcapsulecollider

Character controller with Rigidbody to apply force

i am scripting a humanoid ploymesh player for soccer and i am getting issues of the player movement. In starting i applied character controller and it worked great but then i have to apply physics like when the player hits the ball or collide with it then the ball will displace in that direction. but the character controller thinks of the ball as a stair and it climbs over the ball instead of applying a force. i applied rigid body with it but it didn't work. then changed the character controller to rigid body only with capsule collider, unfortunately, capsule collider doesn't fill the whole human body i mean it leaves the feet of the player. i tried to move the player with the capsule collider above the feet so it doesnt touch the ground. so when i play the feets were in the ground instead of on the ground. so i add box colloder with rigid body to both the foot of player. but and then applied script it doesnt allow the player tomove instead the player only rotate its poistion and i didnt applied isKinematice=false. I will attach my script with it. And please if you have any advice according to my problem please share with me i would love to read it.



using System.Collections; using System.Collections.Generic; using UnityEngine;

public class PlayerMovement : MonoBehaviour { CharacterController myControls;

 public Transform cam;
 [SerializeField]
 private  Rigidbody playerRB;

// [SerializeField] //private Rigidbody leftFootRB; //SerializeField] // Rigidbody rightFootRB;

 public float speed = 5f;
 public float turnSmoothTime = 0.1f;
 public float turnSmoothVelocity;
 // Start is called before the first frame update
 void Start()
 {
    /// myControls = GetComponent<CharacterController>();
    playerRB = GetComponent<Rigidbody>();

 }

 // Update is called once per frame
 void Update()
 {
     float horizontal = Input.GetAxisRaw("Horizontal");
     float vertical = Input.GetAxisRaw("Vertical");

     Vector3 movement = new Vector3(horizontal, 0f, vertical).normalized;
     //playerRB.AddForce(Vector3.forward * speed * vertical);
     //playerRB.AddForce(Vector3.right * speed * horizontal);

     if (movement.magnitude >= 0.1f) {
         float angle = Mathf.Atan2(movement.x, movement.z)*Mathf.Rad2Deg +cam.eulerAngles.y;
         float smoothRotate = Mathf.SmoothDampAngle(transform.eulerAngles.y,angle,ref turnSmoothVelocity,turnSmoothTime);

         transform.rotation = Quaternion.Euler(0, smoothRotate, 0);

         Vector3 mouseMoveDir = Quaternion.Euler(0, angle, 0)*Vector3.forward;
         // playerRB.MovePosition(mouseMoveDir.normalized * Time.deltaTime * speed);
         playerRB.AddForce(movement.normalized* speed);
         //leftFootRB.AddForce(mouseMoveDir.normalized * Time.deltaTime * speed);
        // rightFootRB.AddForce(mouseMoveDir.normalized * Time.deltaTime * speed);
         //myControls.Move(mouseMoveDir.normalized * Time.deltaTime * speed);
         //playerRB.AddForce(mouseMoveDir.normalized * vertical * speed * Time.deltaTime);


     }

 }

}


The commented lines are showing the experiments i have already worked on. Thank you

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

190 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Having problems with animation and character controller velocity not matching 0 Answers

Character falls thru to his waist 11 Answers

Mecanim Rigidbody character slope limit issue 1 Answer

Why do CharacterController objects not come in different collision shapes? 0 Answers

CharacterController.move called on inactive controller 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