Комментарии:
thanks, youre a legend mate
ОтветитьI was trying to get this to work but the gravity and speed and etc. weren't able to be changed using the Character controller script all time see is it saying that its a script
Ответитьusing System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class RigidbodyMovement : MonoBehaviour
{
private Vector3 PlayerMovementInput;
private Vector2 PlayerMouseInput;
private float xRot;
[SerializeField] private LayerMask FloorMask;
[SerializeField] private Transform FeetTransform;
[SerializeField] private Rigidbody PlayerBody;
[SerializeField] private Transform PlayerCamera;
[Space]
[SerializeField] private float Speed;
[SerializeField] private float Sensitivity;
[SerializeField] private float JumpForce;
void Start()
{
Cursor.lockState = CursorLockMode.Locked;
}
// Update is called once per frame
void Update()
{
PlayerMovementInput = new Vector3(Input.GetAxis("Horizontal"), 0f, Input.GetAxis("Vertical"));
PlayerMouseInput = new Vector2(Input.GetAxis("Mouse X"), Input.GetAxis("Mouse Y"));
MovePlayer();
MovePlayerCamera();
}
private void MovePlayer()
{
Vector3 MoveVector = transform.TransformDirection(PlayerMovementInput) * Speed;
PlayerBody.velocity = new Vector3(MoveVector.x, PlayerBody.velocity.y, MoveVector.z);
if (Input.GetKeyDown(KeyCode.Space))
{
if (Physics.CheckSphere(FeetTransform.position, 0.1f, FloorMask))
{
PlayerBody.AddForce(Vector3.up * JumpForce, ForceMode.Impulse);
}
}
}
private void MovePlayerCamera ()
{
xRot -= PlayerMouseInput.y * Sensitivity;
xRot = Mathf.Clamp(xRot, -90f, 90f);
transform.Rotate(0f, PlayerMouseInput.x * Sensitivity, 0f);
PlayerCamera.transform.localRotation = Quaternion.Euler(xRot, 0f ,0f);
}
}
For anyone who has a problem with moving diagonally doubling movement speed, locate the following line within your MovePlayer() function:
Vector3 MoveVector = transform.TransformDirection(PlayerMovementInput);
Now replace it with this line:
Vector3 MoveVector = transform.TransformDirection(Vector3.ClampMagnitude(PlayerMovementInput, 1f));
This let's us set the maximum magnitude that PlayerMovementInput can have to equal 1.
Explanation:
PlayerMovementInput the way we've defined it, gets its magnitude value from our input axis. This means that when we press W, the vector would have a value of 1 in the z direction. The problem comes when we press two keys at once, like W and D. Now the vector's value will be 1 in the z direction PLUS 1 in the x direction, doubling our intended value for PlayerMovmentInput and by extension, MoveVector when it is used elsewhere. Vector3.ClampMagnitude(*your Vector3 here*, *your value here*) lets us keep the direction component of the vector, while limiting the magnitude to whatever value we choose, in this case 1.
One alternative solution would be to normalize PlayerMovementInput like so:
Vector3 MoveVector = transform.TransformDirection(PlayerMovementInput.normalized);
What this does is set the magnitude of our Vector3 to 1. That's it. It's either nothing, or 1. This works, but it loses the smoothing effect of the Input.GetAxis we used to get our inputs, making movement jerky and unpleasant. I wouldn't recommend it in this instance.
If the script from the outside gives the player a velocity (AddForce X, Z), it will not work on him. Bad example
ОтветитьThanks for posting this. Maybe you can help me sort an issue I am having. I got my character moving and all like I wanted but when i try to use it (rigidbody) to detect and use steps, it stalls, bounces or get stuck to things when jumping, even when i have zero friction physics material on something like a wall collider.
Also be i try to make it move backwards with the cam i been working on, something with the camera stops it from backing up and makes it skip forward. The code for the cam is the biggest of the two scripts.
i really really REALLY HATED THIS VIDEO IT DID NOT HELP ME AT ALL
ОтветитьNice Job
ОтветитьExtremely helpful! I was looking forever for a tutorial 3rd person with only rigidbody... Thanks! 😊
ОтветитьI don't like that this changes the velocity directly instead of using a force.
ОтветитьWHY serialized field float? etc
type just public float
LOL wtf ???
Do you know why rotate is moving the object instead of rotating it on my side?
Ответитьthe charater controller movement script doesnt work, the thing where i put the values in doesn show it just says (Script)
ОтветитьThanks!
Ответитьwhat about mathf.clamp ?
Ответитьnothing showed up on my script and some of the code was different from yours
Ответитьi dont see a character controller script?
ОтветитьI have had some problems whit the rigidbody controller so thanks grate vid!!
Ответитьi dont know what i did wrong but my character can only move left and right
ОтветитьSource code?
ОтветитьHI thanks alot
I was searching google, ~coping~ inspiration Ing code, and everything gave some stupid error
This was really helpful, followed along with the video and it is pretty good. Not the world's best character controller but good enough for me, starting out with unity.
SO Thanks
Whenever I bump into something my character starts slowly spinning on the y axis?
Ответитьdoes somebody know how to disable looking up and down???
Ответитьusing System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class RigidbodyMovement : MonoBehaviour
{
private Vector3 PlayerMovementInput;
private Vector2 PlayerMouseInput;
private float xRot;
[SerializeField] private LayerMask FloorMask;
[SerializeField] private Transform FeetTransform;
[SerializeField] private Rigidbody PlayerBody;
[SerializeField] private Transform PlayerCamera;
[Space]
[SerializeField] private float Speed;
[SerializeField] private float Sensitivity;
[SerializeField] private float JumpForce;
void Start()
{
Cursor.lockState = CursorLockMode.Locked;
}
// Update is called once per frame
void Update()
{
PlayerMovementInput = new Vector3(Input.GetAxis("Horizontal"), 0f, Input.GetAxis("Vertical"));
PlayerMouseInput = new Vector2(Input.GetAxis("Mouse X"), Input.GetAxis("Mouse Y"));
MovePlayer();
MovePlayerCamera();
}
private void MovePlayer()
{
Vector3 MoveVector = transform.TransformDirection(PlayerMovementInput) * Speed;
PlayerBody.velocity = new Vector3(MoveVector.x, PlayerBody.velocity.y, MoveVector.z);
if (Input.GetKeyDown(KeyCode.Space))
{
if (Physics.CheckSphere(FeetTransform.position, 0.1f, FloorMask))
{
PlayerBody.AddForce(Vector3.up * JumpForce, ForceMode.Impulse);
}
}
}
private void MovePlayerCamera ()
{
xRot -= PlayerMouseInput.y * Sensitivity;
xRot = Mathf.Clamp(xRot, -90f, 90f);
transform.Rotate(0f, PlayerMouseInput.x * Sensitivity, 0f);
PlayerCamera.transform.localRotation = Quaternion.Euler(xRot, 0f ,0f);
}
}
I was halfway through the code when I realized this was a third person camera (I'm making a first-person game)
Ответитьdoes not work. i dont know why but the vertical movement does not work and my player just flips in the air. i have tried constraints and even making a frictionless surface but it just flips around and doesnt move forward or backwards at all.
Ответить@Rytech so for some reason my a and d keys switch during movement, any idea?
Ответитьnice tutorial !!!
Ответитьnothing work i only get erorrs plus this happens on every tutorial i watch
Ответитьto many errors L vid
Ответитьamazing
ОтветитьI use rigidbody and when i move my camera horisontally while straifing my player shake seriously, resulting in a very bad visual effect(
i used void update instead of fixedupdate (fixed makes camera rotate at 50fps while the game is at 500) and normalised movement vector with deltatime.
also i use rigidbody.MoveRotation(rigidbody.rotation * quaterion (it is Quaternion.Euler(0f, PlayerMouseInput.x* mouseSensivity, 0f)) so it is a bit less shaky but still not good
Why is Character Controller not going into the Controller thing where you have to add all the variables at the end help please i get drag the character controller variable into the controller thingy Please i need heplepwktkppppppppppppppppp 😁😁😁😁😁😁😁😁😁😃😃😀🤣😉🤗🤗🤗😬😬😬😬😬😬😬😬😬😬😬😬😬😬😔😪😪😪😑😐😐😐😐😐😐😐😐😐😐😐😐😐😛😛😛😛😛😊😊😊😊😊😊😴😴😴😴😴😴😴😴😴😷😷😷😷😷😷😷😷😷😷😷😷😷😷😷😷😷🥵🥵🥵🥵🥵🥵🥶🥶😌😌🥶🥶🥶🥶🥶🥶🥶👺👺👺👺👺👺👺👺👺👺👺👺👺👺👺👺🖤🖤🖤🖤🖤🖤🖤🖤🖤🖤🖤🖤🖤🖤🖤💟🖤🖤🖤🖤💙💙💙🖤🖤🖤🖤🖤🖤🖤🖤🖤🖤🖤🖤🖤🖤🖤🖤🖤🖤🖤🖤🖤🖤🖤🖤🖤🖤🖤🖤🖤🖤🖤🖤🖤🖤🖤🖤🖤💙💙💙🖤🖤🖤🖤🖤🖤🖤🖤🖤🖤🖤🖤🖤🖤🖤🖤🖤🖤🖤🖤🖤🖤🖤🖤🖤🖤🖤🖤🖤🖤🖤🖤🖤🖤🖤🖤🖤💙💙💙🖤🖤🖤🖤🖤🖤🖤🖤🖤🖤🖤🖤🖤🖤🖤🖤🖤🖤🖤🖤🖤🖤🖤🖤🖤🖤🖤🖤🖤🖤🖤
Ответитьif anyone had problems with the feet "isGrounded", like I had. Try making the radius smaller e.g. " Physics.CheckSphere(FeetTransform.position, 0.001f , defaultMask "
Ответитьthank you so much
ОтветитьSpent Six Hours Copying over the script but otherwise great Giude!
ОтветитьESTOS ERRORES COMETIEN EL TUTORIAL:
- No me fige en los " -= " por lo lo que no me daba resultados
-- No agregue "
private void Start()
{
Cursor.lockState = CursorLockMode.Locked;
}
"
gran tutorial thanks
I wonder why this isn't built in it takes a really long time to do so why isn't it built in?
ОтветитьThsnks for video i needed the help!!!! 🙌🏾
Ответитьthank you soo much im new to unity and i just learned this rom you! i subbed
ОтветитьI exactly looking for this since a Day, But at last i found you so this made my Day : )
Ответитьhey ya can i just have the code my brain is frying at the sight of this code all i know how to do in unity is make simple forward backward pan left and pan right and maybe rigid body physics with it too
ОтветитьCOULD YOU ATLEAST PUT THE SCRIPT IN THE DESCRIPTION?
Ответитьusing System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class RigidbodyMovement : MonoBehaviour
{
private Vector3 PlayerMovementInput;
private Vector2 PlayerMouseInput;
[SearailizeField] private Transform PlayerCamera;
[SearailazeField] private Rigidbody PlayerBody;
[Space]
[SearailazeField] private float Speed;
[SearailazeField] private float Sensitivity;
[SearailazeField] private float Jumpforce;
private void Update()
{
PlayerMovementInput = new Vector3(Input.GetAxis("Horizontal"), 0f, PlayerMovementInput.GetAxis("Vertical"));
PlayerMouseInput = new Vector2(Input.GetAxis("Mouse X"), PlayerMouseInput.GetAxis("Mouse Y"));
MovePlayer();
MovePlayerCamera();
}
private void MovePlayer()
{
Vector3 MoveVector = transform.TransformDirection(PlayerMovementInput) * Speed;
PlayerBody.velocity = new Vector3(MoveVector.x, PlayerBody.velocity.y, MoveVector, z);
if (Input.GetKeyDown(KeyCode.Space))
{
PlayerBody.AddForce(Vector3.up * Jumpforce, ForceMode.Impulse);
}
}
private void MovePlayerCamera()
{
}
}