Hello! im new in unity and I don’t have a lot of skills in coding, I am trying to make a simple movement systeme for my “player” which is a cube, I can make it move nicely in each direction perfectly. here’s the script im using at this moment:
using UnityEngine;
using System.Collections;
public class playerMovement : MonoBehaviour {
public float moveSpeed;
private float maxSpeed = 5f;
public GameObject deathParticles;
private Vector3 spawn;
private Vector3 input;
// Use this for initialization
void Start () {
spawn = transform.position;
}
// Update is called once per frame
void Update () {
input = new Vector3 (Input.GetAxis ("Horizontal"), 0, Input.GetAxis ("Vertical"));
if (rigidbody.velocity.magnitude < maxSpeed)
{
rigidbody.AddRelativeForce (input * moveSpeed);
}
if(transform.position.y < -5)
{
Die ();
}
}
void OnCollisionEnter(Collision other)
{
if(other.transform.tag == "Enemy")
{
Die();
}
}
void OnTriggerEnter(Collider other)
{
if(other.transform.tag == "Goal")
{
GameManager.CompleteLevel();
}
}
void Die()
{
Instantiate(deathParticles, transform.position, Quaternion.identity);
transform.position = spawn;
}
}
I have a mouse orbit camera attached to it and I would like to know how to push my cube in the direction my mouse is pointing instead of only going in one the direction the block is facing.
Hope it’s not too complicated ![]()
Thanks