- Home /
Problem is not reproducible or outdated
Applying force, rotation, physics and stable movement to objects.
I'm creating an asteroid Dodging game with the simple point of scoring points the more asteroids you dodge. I'm using the Unity standard to rotate my ship giving the illusion of banking however when I also apply movement to this the ship moves in the direction of the rotation i.e: when I bank left the ships position is moving parallel to the angle so if it is now angled left the ship will now move up and right(north east direction) the opposite if I bank right the ship will move north west (going up+y and left-x) which is not what I wish for. I would like my ship to bank left and right but stay on the same y position and only move left and right . My current movement code is below:
using UnityEngine; using System.Collections;
public class shuttleControl : MonoBehaviour {
float speed = 50f;
public float tiltAngle = 30.0F;
public float smooth = 2.0F;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
float h = Input.GetAxis("Horizontal") * Time.deltaTime * speed;
float tiltAroundZ = Input.GetAxis("Horizontal") * tiltAngle;
Quaternion target = Quaternion.Euler(0, 0, tiltAroundZ);
transform.rotation = Quaternion.Slerp(transform.rotation, target, Time.deltaTime * smooth);
transform.Translate(h,0,0);
}
}
Adding to this I would like to add physics the ship itself and the asteroids that it comes in contact with, I would like the asteroids to simply bounce off the ship (it has shields and every bounce will lower them until no more shields in which case the next time it collides with an asteroid it will call the blow up animation and end the game- I will work on this part later when I have the basics of the game working) what would I need on both objects to create this effect? I tried adding a mesh collider to the ship with a rigidbody but for some reason that sends the ship crazy with a floating point error appearing stating: "Due to floating-point precision limitations. it is recommended to bring the world coordinates of the game object within a smaller range" and the X Y Z coordinates of the ship have gone into overdrive. (this happens also to the asteroid should I do the same thing.
Finally I would like to instantiate the asteroids as random positions relative to the ship but in visual range, vary the size and randomize the movement and rotation.
Any help would be appreciated. I've tried to explain as best I can, I can clarify if points seem unclear.
Thanks,
Euden
EDIT: Although an answer as to how to keep it on the same axis it appreciated I have come up with a temporary solution which is to allow the ship to tilt at all angles by including the vertical axis also. this however, does not solve the physics problem and I would prefer to be able to tilt left and go left only without changing my Y position at all so only x and z are affected etc.
I am using Unity's physics, so I am adding rigid body's to the ship and the asteroids which seem to be fine, its when I add a collider to either of them do I get the crazy movement. Neither of them are being animated the physics are strictly using unity's components.
You are asking multiple questions here. You need to edit this post to a single question and then post your other question each with their own question. This is both the rule of site as well as a practical consideration. For example, I know the answer to some of your questions, but not all, so I'm unlikely to answer. Plus once a partial answer is posted, you are less likely to get any follow-up answers to any unanswered portions.