I have a problem when I move the ship with joystick it doesnt tilt…
using UnityEngine;
using System.Collections;
using UnitySampleAssets.CrossPlatformInput;
public class MoverNave : MonoBehaviour {
float sense = 5;
public float speed;
public float tilt;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
transform.Translate (new Vector3 (0, CrossPlatformInputManager.GetAxis ("Vertical")) * Time.deltaTime * speed);
float y = CrossPlatformInputManager.GetAxis("Mouse Y") * sense;
transform.Rotate(0,y,0);
transform.Translate (new Vector3 (CrossPlatformInputManager.GetAxis ("Horizontal"),0) * Time.deltaTime * speed);
float x = CrossPlatformInputManager.GetAxis("Mouse X") * sense;
transform.Rotate(x,0,0);
Vector3 movement = new Vector3(CrossPlatformInputManager.GetAxis("Horizontal"), CrossPlatformInputManager.GetAxis("Vertical"), 0.0f);
GetComponent<Rigidbody>().velocity = movement * speed;
GetComponent<Rigidbody>().rotation = Quaternion.Euler(0.0f, 0.0f, GetComponent<Rigidbody>().velocity.x * -tilt);
}
}
I don’t understand the problem, but I do see that you have a weird mixture of physics and non-physics movement here. You’re directly manipulating the transform position, and the rigidbody position, and the velocity too!
Please decide whether you want to use physics or no physics (I recommend no physics, unless you have a good reason why physics is necessary). And then use only the methods appropriate for that.
Or in other words: muck with the Transform (with Rigidbody removed or set to kinetic), or with the Rigidbody, but never muck with both.
Ok sorry, Ive been changing the context of the topic because I found a solution to the problem…but Now my problem is how I can tilt the ship when I move to sideways with the joystick. Do you know that?
[quote=“JoeStrout, post:4, topic: 626281, username:JoeStrout”]
Yes, but how you do it depends on whether or not you’re using physics. Two completely different answers.
[/quote]Sorry Again…
I want to use no physics. How I can do that? If you can help me please