- Home /
How to make a normalized movement script?
I have a simple normalized movement script ,but how could I add jumping? Is there a better way to do this so that I can have running speeds and such? I want to have a script like the FPSWalkerEnhanced script ,but that has normalized movement. Any help would be great! Thanks! Here's the script: using UnityEngine; using System.Collections;
//
//THIS SCRIPT CONTROLS THE MOVEMENT OF THE PLAYER
//
public class PlayerMovement : MonoBehaviour
{
//ALL OF THE PUBLIC VARIABLES
public float walkSpeed = 6.0f;
public float runSpeed = 12.0f;
//ALL OF THE PRIVATE VARIABLES
private Vector3 moveDirection;
private float speed;
void Start ()
{
speed = walkSpeed;
}
void Update ()
{
moveDirection = new Vector3 (Input.GetAxisRaw ("Horizontal"),0, Input.GetAxisRaw ("Vertical")).normalized;
}
void FixedUpdate()
{
rigidbody.MovePosition (rigidbody.position + transform.TransformDirection(moveDirection) * speed * Time.deltaTime);
}
}
Answer by RetepTrun · May 23, 2014 at 02:34 AM
Use raycast.
Cast down, get back a hit and then rotate yourself normal to the hit.
Can you show some example script of how I could do this?
From one of my scripts should give you more of an idea you need to change ray to make it point down rotate yourself to r
void FixedUpdate () { Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit hit; if (Physics.Raycast((ray),out hit)){ aimPoint=hit.point; thing.position=aimPoint; Vector3 r =hit.point.normalized; //focus here } }
Your answer
Follow this Question
Related Questions
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
WheelColliders Bug Fix 0 Answers
Smooth Player Movement 1 Answer