- Home /
Question by
manueldx1 · Aug 03, 2016 at 06:38 AM ·
input setting
I am trying to make my game respond to a command using my keyboard on my MAC. Here is what I have and it is giving me problems. I have the gravity down, but my character will not move if I press a button on my keyboard to command it.
using UnityEngine; using System.Collections;
public class NewBehaviourScript : MonoBehaviour {
Vector3 velocity = Vector3.zero;
public Vector3 gravity;
public Vector3 flapVelocity;
public float maxSpeed = 5f;
public float forwardSpeed = 1f;
bool didFlap = false;
// Use this for initialization
void Start () {
}
// Dographic and input updates here
void update() {
if(Input.GetKeyDown(KeyCode.Space) || Input.GetMouseButtonDown(0) ) {
didFlap = true;
}
}
// Do physics engine update here
void FixedUpdate () {
velocity.x = forwardSpeed;
velocity += gravity * Time.deltaTime;
if (didFlap == true) {
didFlap = false;
if (velocity.y < 0)
velocity.y = 0;
velocity += flapVelocity;
}
velocity = Vector3.ClampMagnitude(velocity, maxSpeed);
transform.position += velocity * Time.deltaTime;
float angle = 0;
if (velocity.y < 0) {
angle = Mathf.Lerp (0, -90, -velocity.y / maxSpeed);
}
transform.rotation = Quaternion.Euler (0, 0, angle);
}
}
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220612090044im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Texture bad Quality 2 Answers
New Unity Input System Getting continuous input 1 Answer
Settings Bug? 0 Answers