- Home /
Character Movement component
hello,
I am new to Unity and I need help!
I am currently watching a tutorial for beginners and I have managed to get to the end pretty well as I was able to follow the instructions perfectly. However the guy on the video adds a component called ""character movement" which on my Unity 5.5 doesn t exist! I ve been trying to use thrid person or first person charact components but they seem to mess u everywthing! I ve been looking everywhere and even on the internet i haven t found a solution.
Please somebody help me!
may be its his own Script made to move the Character you should check the tutorial further i am sure he will explain that script follow the tutorial closely
i ve watched the tutorial closely more tha once and followed it carefully but it doesn t explain that part, i just don t seem to have that particular component.
You may be confusing it with the "character controller" physics component, but most people do write their own script for character movement.
so... i m going to write down how the tutorial proceeded:
add component > physics > character controller
i did this part, then...
add component > scripts > character movement
unfortunately, when i went to do that, there was not "character movement" component. I m VERY new to unity, but i have assumed he coded and saved previously. I m trying to code as well, i ve made my own script... but my character slowly sinks through the terrain ahah
Answer by Scholand · Jan 28, 2017 at 11:59 PM
You Can use this for a smooth or direct 2DCamera Movement.
using UnityEngine; using System.Collections;
public class CameraMovment : MonoBehaviour {
private Vector2 velocity;
public float smoothTimeY;
public float smoothTimeX;
public float DownDeadPoint = 0;
private GameObject player;
void Start ()
{
player = GameObject.FindGameObjectWithTag("Player");
}
void FixedUpdate()
{
if(player == null)
{
player = GameObject.FindGameObjectWithTag("Player");
}
if (player == null)
{
Debug.Log("Error: no Player found");
return;
}
float posX;
if(player.transform.position.x >= 5)
{
posX = Mathf.SmoothDamp(transform.position.x, player.transform.position.x, ref velocity.x, smoothTimeX);
}
else
{
posX = Mathf.SmoothDamp(transform.position.x, 5, ref velocity.x, smoothTimeX);
}
float posY;
if (player.transform.position.y >= DownDeadPoint)
{
posY = Mathf.SmoothDamp(transform.position.y, player.transform.position.y, ref velocity.y, smoothTimeY);
}
else
{
posY = Mathf.SmoothDamp(transform.position.y, DownDeadPoint, ref velocity.y, smoothTimeY);
}
transform.position = new Vector3(posX, posY, transform.position.z);
}
}
wow... i ll try that thank you!
i went ahead and made a personal script, which it seems to work, but the character slowly sinks through the terrain. ahah
I will give a shot with yours and i ll let you know how it goes!
tnx again
Answer by Kikottan · Jan 30, 2017 at 07:44 AM
let me upload the script i ve done...
using UnityEngine; using System.Collections;
public class PlayerController : MonoBehaviour {
public float inputDelay = 0.1f;
public float forwardVel = 12;
public float rotateVel = 100;
Quaternion targetRotation;
Rigidbody rBody;
float forwardInput, turnInput;
public Quaternion TargetRotation
{
get {return targetRotation; }
}
void Start()
{
targetRotation = transform.rotation;
if (GetComponent<Rigidbody>())
rBody = (GetComponent<Rigidbody>());
else
Debug.LogError("The character needs a rigidbody.");
forwardInput = turnInput = 0;
}
void GetInput()
{
forwardInput = Input.GetAxis("Vertical");
turnInput = Input.GetAxis("Horizontal");
}
void Update()
{
GetInput();
Turn();
}
void FixedUpdate()
{
Run();
}
void Run()
{
if (Mathf.Abs(forwardInput) > inputDelay)
{
//move
rBody.velocity = transform.forward * forwardInput * forwardVel;
}
else
//zero velocity
rBody.velocity = Vector3.zero;
}
void Turn()
{
if (Mathf.Abs (turnInput) > inputDelay)
{
targetRotation *= Quaternion.AngleAxis(rotateVel * turnInput * Time.deltaTime, Vector3.up);
}
transform.rotation = targetRotation;
}
}
Your answer
Follow this Question
Related Questions
Object reference not set to an instance of an Object 1 Answer
Get raw script of a Unity component 2 Answers
Detect collision when changing character controller height 2 Answers
Trouble disabling and enabling components on charactercontroller 1 Answer
Increasing Camera "Bobbing" speed when character is sprinting 1 Answer