Hi there!
I am prototyping a Mario Galaxy style (“faux”) gravity system. While the attraction force didn’t give me much trouble, the controls are giving me a headache.
You can move. You can jump. But when you do both things simultaneously, everything goes whack.
This is my bare-bones code:
using UnityEngine;
using System.Collections;
public class PlayerController : MonoBehaviour {
private float moveSpeed = 15;
private Vector3 moveDirection;
void Start() {
}
void Update() {
moveDirection = new Vector3(Input.GetAxisRaw("Horizontal"),0,Input.GetAxisRaw("Vertical")).normalized;
}
void FixedUpdate() {
rigidbody.MovePosition (rigidbody.position + transform.TransformDirection (moveDirection) * moveSpeed * Time.deltaTime);
}
void OnCollisionStay (Collision col)
{
if (Input.GetKeyDown (KeyCode.Space))
rigidbody.velocity += transform.up * 20;
}
}
Any leads?
Thanks a lot in advance!