C# Only please This is also a 3D project semi-top down view.
Hello, I was wondering how I can make this white cube (the player) snap to the yellow cube in the direction pressed and then return back to the starting position that the white cube (the player) is in smoothly.(Won’t a slerp come into play when trying to make the cube return smoothly to the starting position?)
My script is not correct and I’m trying to understand what is wrong.
I just want the cube to move to one of the yellow squares in the direction pressed [ w key moves the cube forward, a key moves the cube left towards the yellow cube, etc] and then snaps to the yellow square for 1 second and returns back to the middle / starting position.
using UnityEngine;
using System.Collections;
public class MoveCube : MonoBehaviour {
public float moveSpeed = 1f;
private Vector3 myPosition;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
if (Input.GetKey(KeyCode.W))
transform.position += new Vector3
(moveSpeed * Time.deltaTime, 0.0f, 1f);
if (Input.GetKey(KeyCode.A))
transform.position += new Vector3
(moveSpeed * Time.deltaTime, -1f, 0.0f);
if (Input.GetKey(KeyCode.S))
transform.position += new Vector3
(moveSpeed * Time.deltaTime, 1f, 0.0f);
if (Input.GetKey(KeyCode.D))
transform.position += new Vector3
(moveSpeed * Time.deltaTime, 0.0f, -1f);
}
}
