hey everyone! i need some help with a simple moving script problem. Just before we go into details, I’m rookie, so detailed “instructions” are welcome
what i want to acchive:
a spaceship which can fly into 4 directions ( up, down, left, right and for diagonally) and a constant “forward” acceleration. it a firstperson view game. Maybe the movement from starfox is an good example, basically an on-rail shooter with this movement.
right now it’s looking like this:
1 gameobject,
our shipour ship forward acceleration (js):
ar moveSpeed = 10.0;
var sideMovement = 10.0;
var upMovement = 10.0;
function Update ()
{
var sideMovement = Input.GetAxis("Horizontal") * moveSpeed;
sideMovement *= Time.deltaTime;
transform.Translate(sideMovement,0,moveSpeed);
var upMovement = Input.GetAxis("Vertical") * moveSpeed;
upMovement *= Time.deltaTime;
transform.Translate(upMovement,0,moveSpeed);
}
our ship movement:
var keyboardSpeed = 20.0;
function FixedUpdate () {
// This is where we move the object.
// Get input from the keyboard, with automatic smoothing (GetAxis instead of GetAxisRaw).
// We always want the movement to be framerate independent, so we multiply by Time.deltaTime.
var keyboardX = Input.GetAxis("Horizontal") * keyboardSpeed * Time.deltaTime;
var keyboardY = Input.GetAxis("Vertical") * keyboardSpeed * Time.deltaTime;
// Calculate the new position based on the above input.
// If you want to limit the movement, you can use Mathf.Clamp
// to limit the allowed range of newPos.x or newPos.y.
var newPos = rigidbody.position + Vector3(keyboardX, keyboardY, 0.0);
// Move the object.
rigidbody.MovePosition(newPos);
}
// Require a Rigidbody component to be attached to the same GameObject.
@script RequireComponent(Rigidbody)
THE PROBLEM:
if we move our ship in any direction (especially in the diagonal ones) the moving animation looks kinda laggy or “not smooth”).
how can we solve this? any script snips & pieces are welcome
EDIT: this was just our first way to do it, i have no problem with replacing the code with an other one!