Комментарии:
adding a rigid body just breaks everything for me. what do i do?
ОтветитьI never understood atan2 before taking trigonometry class, but now it all just clicked!
Ответитьscript if you are lazy
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Playermovement : MonoBehaviour
{
public CharacterController controller;
public Transform cam;
public float speed = 6f;
public float turnSmoothTime = 0.1f;
float turSmoothVelocity;
// Start is called before the first frame update
void Start()
{
Cursor.lockState = CursorLockMode.Locked;
}
// Update is called once per frame
void Update()
{
float horizontal = Input.GetAxisRaw("Horizontal");
float vertical = Input.GetAxisRaw("Vertical");
Vector3 direction = new Vector3(horizontal, 0f, vertical).normalized;
if(direction.magnitude >= 0.1f)
{
float targetAngle = Mathf.Atan2(direction.x, direction.z) * Mathf.Rad2Deg + cam.eulerAngles.y;
float angle = Mathf.SmoothDampAngle(transform.eulerAngles.y, targetAngle, ref turSmoothVelocity, turnSmoothTime);
transform.rotation = Quaternion.Euler(0f, angle, 0f);
Vector3 moveDir = Quaternion.Euler(0f, targetAngle, 0f) * Vector3.forward;
controller.Move(moveDir.normalized * speed * Time.deltaTime);
}
}
}
does this work these days even when brackey's gone?
ОтветитьCODE:
// Using Character controller component and using old input method
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ThirdPersonMovement : MonoBehaviour
{
public CharacterController controller;
public Transform cam;
public float speed = 6f;
public float turnSmoothTime = 0.1f;
float turnSmoothVelocity;
// Update is called once per frame
void Update()
{
float horizontal = Input.GetAxisRaw("Horizontal");
float vertical = Input.GetAxisRaw("Vertical");
Vector3 direction = new Vector3(horizontal, 0f, vertical).normalized;
if (direction.magnitude >= 0.1f)
{
float targetAngle = Mathf.Atan2(direction.x, direction.z) * Mathf.Rad2Deg + cam.eulerAngles.y;
float angle = Mathf.SmoothDampAngle(transform.eulerAngles.y, targetAngle, ref turnSmoothVelocity, turnSmoothTime);
transform.rotation = Quaternion.Euler(0f, angle, 0f);
Vector3 moveDir = Quaternion.Euler(0f, targetAngle, 0f) * Vector3.forward;
controller.Move(moveDir.normalized * speed * Time.deltaTime);
}
}
}
the code did not work😭
ОтветитьIf I walk to the side my camera will keep looking at my character instead of following it, resulting in the character walking circles around the camera.
Does anyone know how I can fix this?
Too sad you stopped making videos here, I still watch your stuff on a regular basis. Thanks for creating!
Ответитьanyone have ideas on how to add physics so the player stays on ground?
ОтветитьDo someone wanna write me a five pages essay how is this movement script working, because Im kinda dumb to understand it.
ОтветитьFor, The new programmers watching this, IF your mouse direction is inverted, Go to cinemachine controller > x axis > turn off invert input
ОтветитьCan someone help, whenever I move my mouse cursor to the left it always moves my camera so it is looking to the right. I have tried inverting everything that has to do with camera movement by adding negatives, and multiplying by negative 1 but nothing works. If someone could please help it would be greatly appreciated.
ОтветитьWeirdly enough my player started facing a different direction than they are travelling, anyone can help with this?
ОтветитьBest
EEEVVERERR
thank u im trying to make a 3rd person platformer
ОтветитьChatGpt gave me a similar code when asking for a third person movement code.
ОтветитьThis is very helpful but how do I implement gravity for the player into this script
ОтветитьI really wish you were a professor at my university
ОтветитьWhy is my Mouse movement for the Camera inverted?? And how can i fix that?
ОтветитьHi, how can i import Jump in this codes?
Ответитьusing System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerMovement : MonoBehaviour
{
public CharacterController controller;
public float Speed;
public float turnSmoothTime;
private float turnSmoothVelocity;
public Transform cam;
void Update()
{
float horizontal = Input.GetAxisRaw("Horizontal");
float vertical = Input.GetAxisRaw("Vertical");
Vector3 direction = new Vector3(horizontal, 0f, vertical).normalized;
if(direction.magnitude >= 0.1f)
{
float targetAngle = Mathf.Atan2(direction.x, direction.z) * Mathf.Rad2Deg + cam.eulerAngles.y;
float angle = Mathf.SmoothDampAngle(transform.eulerAngles.y, targetAngle, ref turnSmoothVelocity, turnSmoothTime);
transform.rotation = Quaternion.Euler(0f, angle, 0f);
Vector3 moveDir = Quaternion.Euler(0,targetAngle,0f) * Vector3.forward;
controller.Move(moveDir.normalized * Speed * Time.deltaTime);
}
}
}
He is noob in teaching mf
Ответитьi was searching for ages how to make san andreas camera thanks
Ответитьfor the script it wont let me add the character controller as the controller
ОтветитьThankyou bro❤❤
Ответитьno one did..so iam doing it.....
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class controllerscript : MonoBehaviour
{
public CharacterController controller;
public Transform cam;
public float speed = 6f;
public float turnSmoothTime = 0.1f;
float turnSmoothVelocity;
// Update is called once per frame
void Update()
{
float horizontal = Input.GetAxisRaw("Horizontal");
float vertical = Input.GetAxisRaw("Vertical");
Vector3 direction = new Vector3(horizontal, 0f, vertical).normalized;
if (direction.magnitude >= 0.1f)
{
float targetAngle = Mathf.Atan2(direction.x, direction.z) * Mathf.Rad2Deg + cam.eulerAngles.y;
float angle = Mathf.SmoothDampAngle(transform.eulerAngles.y, targetAngle, ref turnSmoothVelocity, turnSmoothTime);
transform.rotation = Quaternion.Euler(0f, angle, 0f);
Vector3 moveDir = Quaternion.Euler(0f, targetAngle, 0f) * Vector3.forward;
controller.Move(moveDir.normalized * speed * Time.deltaTime);
}
}
}
For all lazy programmers:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerMoveController : MonoBehaviour
{
public Transform cam;
public CharacterController controller;
public float speed = 6;
public float turnSmoothTime = 0.1f;
float turnSmoothVelocity;
void Update()
{
float horizontal = Input.GetAxisRaw("Horizontal");
float vertical = Input.GetAxisRaw("Vertical");
Vector3 direction = new Vector3(horizontal, 0, vertical).normalized;
if (direction.magnitude >= 0.1f)
{
isMoving = true;
float targetAngle = Mathf.Atan2(direction.x, direction.z) * Mathf.Rad2Deg + cam.eulerAngles.y;
float angle = Mathf.SmoothDampAngle(transform.eulerAngles.y, targetAngle, ref smoothTurnVelocity, smoothTurnTime);
transform.rotation = Quaternion.Euler(0, angle, 0);
Vector3 moveDir = Quaternion.Euler(0f, targetAngle, 0f) * Vector3.forward;
controller.Move(moveDir.normalized * speed * Time.deltaTime);
}
}
}
I'm having a hard time trying to implement the ability to JUMP, while using this script. Any help would be much appreciated!
ОтветитьWait but how can we code the jump??
ОтветитьAmazing tutorial really easy to understand love this and you❤❤❤
ОтветитьLegend Brackeys
Ответитьdid not work
Ответить! I was trying to make a third person camera system for my game but it wasn't really working. Despite the differences in setup, this worked for me without having to change much. Thanks for making this tutorial so flexible/customisable
ОтветитьCan you send me a link to your third person movement script pleas mine isn’t working I’ve follows step by step but still nothing
Ответитьim too lazy too rewrite the script and oh hell nah im not downloading that. can someone please rewrite it so i can copy paste?
Ответитьit is going forwerd when i jump.
Ответитьbean
Ответитьthere was less space in room so he just rome around the table lol
Ответитьroom me jagye kam pas rahi thi to aak table ka hi chakar kat liya
Ответитьthe camera direction while on play mode are inversed can some one help?
Ответитьmy unity is telling to Assets\ThirdPersonMovement.cs(20,64): error CS1002: ; expected
pls help heres my scipt
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ThirdPersonMovement : MonoBehaviour
{
public CharacterController controller;
public float speed = 6f;
// Update is called once per frame
void Update()
{
float Horizontal = Input.GetAxisRaw("Horizontal");
float Vertical = Input.GetAxisRaw("Vertical");
Vector3 direction = new Vector3(Horizontal, 0f, Vertical).normalized;
if (direction.magnetude >= 0.1f)
{
controller.move(direction * speed * Time.deltaTime)
}
}
}
its the same from tutorial
🥲
This tutorial was so good that I could feel the third person movement coming inside me whenever i played my game
Ответитьthanks done the turorial
Ответитьhippity hoppity your code is now my property
Ответитьyou're great
Ответитьwhen making to cinemamachine nothing worked for me. any help?
Ответитьunity is giving me this code: Assets\thirdpersonmovement.cs(21,78): error CS0117: 'Mathf' does not contain a definition for 'Rad2deg'
anyone know how to fix this? please help