- Home /
Closed by thread maker for outdated and overused
Unity 3d(Space) Questions
Hey everyone got some questions and yes I know Im total noob…
How can I improve my ship movement script? It seems a bit buggy when turning for some reason almost like bending space but its ok I guess…also how can I tilt the ship slightly when turning? I am going for a STO style ship control system thing.
using UnityEngine;
using System.Collections;
public class ShipControl : MonoBehaviour {
public Transform ship; float flyingSpeed = 0; float turnSpeed = 50.0f; void Update () { //Accelerate the ship using the thrust key. if(Input.GetKeyDown("e")) { if(flyingSpeed == 0) { flyingSpeed = 2.5f; ship.transform.Translate(0,-flyingSpeed * Time.deltaTime,0); } if(flyingSpeed == 2.5f) { flyingSpeed = 5f; ship.transform.Translate(0,-flyingSpeed * Time.deltaTime,0); } } //Decelerate the ship using the thrust button. if(Input.GetKeyDown("q")) { if(flyingSpeed == 5f) { flyingSpeed = 2.5f; } if(flyingSpeed == 2.5f) { flyingSpeed = 0; } } if(Input.GetKey("w")) { ship.transform.Rotate(20.0f * Time.deltaTime, 0.0f, 0.0f); } if(Input.GetKey("s")) { ship.transform.Rotate(-20.0f * Time.deltaTime, 0.0f, 0.0f); } if(Input.GetKey("d")) { ship.transform.Rotate(0.0f, turnSpeed * Time.deltaTime, 0.0f * Time.deltaTime, Space.World); //and then turn the plane } if(Input.GetKey("a")) { ship.transform.Rotate(0.0f, -turnSpeed * Time.deltaTime, 0.0f * Time.deltaTime, Space.World); //and then turn the plane } ship.transform.Translate(0,-flyingSpeed * Time.deltaTime,0); } }
Edit: Solved!
Edit: Solved!
Is there a way I can make two ships collide by just making a collision sphere on both that detect each other? I don't need all the fancy physics, using transform for movement currently.
You should really start a new question as this one will get messy with all the updates... but for simple sphere collision check you can easily do this yourself:
(obj1.transform.position - obj2.transform.position).magnitude < (obj1.colliderRadius + obj2.colliderRadius)
Where colliderRadius is whatever the sphere radius should be on each object.
Answer by tanoshimi · Oct 27, 2013 at 07:25 AM
Lots of possible approaches: simplest is to create a new sphere gameobject, use a semitransparent, emissive material (to give a "glow"), make it a child of your spaceship object and centre it by setting x,y,z translation to 0
Yep - attach a sphere collider and rigidbody component to each ship, but select "is kinematic" because you'll be moving them yourself. Then you can write code that listens to the OnCollisionEnter () event
I have a problem… I added a Ridgidbody to both ships and use is $$anonymous$$inematic, unchecked gravity, and set angular drag to zero for both ships. But now I have 999 actor errors saying "Actor::update$$anonymous$$assFromShapes:Compute mesh inertia tensor failed for one of the actor's mesh shapes! Please change mesh geometry or supply a tensor manually!" what on earth does this mean? I am not looking for physics such as inertia or drag or anything just need to check the collision of my ship I move with transform script.