- Home /
Question by
NAKRUF · Nov 28, 2016 at 08:02 AM ·
c#movement scriptdirection
Backwards movment is slow relative to forwards
I'm a beginner to Unity and I wanted to create one of the most simple things and for some reason, I can't do it. What I wanted is a script that moves the character towards mouse direction and changes speed with w and s that is constant if not changed.
If someone could help i would be happy!
using UnityEngine;
using System.Collections;
public class ShipController : MonoBehaviour
{
public float max_speed_direction = 30;
public float max_speed_xy = 20;
public float acc_speed_direction = 2;
public float acc_speed_xy = 1;
private float current_speed_direction;
private float current_speed_right;
private float current_speed_up;
private float Direction_value;
// Use this for initialization
void Start()
{
}
// Update is called once per frame
void Update()
{
if (Input.GetAxis("Vertical") != 0)
current_speed_direction = (current_speed_direction>max_speed_direction)? max_speed_direction : (current_speed_direction + acc_speed_direction) * Input.GetAxis("Vertical");
transform.Translate(Vector3.forward * current_speed_direction);
}
}
Comment
Your answer
Follow this Question
Related Questions
Distribute terrain in zones 3 Answers
How to change player direction with one button?,How do I make one button change direction of player? 0 Answers
Player rotating towards direction of movement in 3D 1 Answer
Multiple Cars not working 1 Answer
An OS design issue: File types associated with their appropriate programs 1 Answer