Hey all having a hard time with making a starship move at all let alone my goal of having a STO style movement. Here’s what I am trying to do…
q=speed down
e=speed up
w=tilt down and continue moving forward
s=tilt up and continue moving forward
a=move left and tilt, still move forward
d=move right and tilt, still move forward
I have not been able to figure it out… the object the scripts suppost to move is a ship model with camera attached, view is perfect but I seem to have left behind impulse engines lol Anyways any help would be great but trying to avoid ridged body code due to fact the model won’t support the ridged body in interface editor. I guess transform.translate(Vector3.forward) but so confused…
Well I kind of got things working but turning just seems wrong… its like it does turns like is orbiting a planet or something… its really hard to explain. Anyways I’m taking suggestions so here is the code…
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);
}
}
Anyone got ideas? Also still need tilting on turning, if you need to see what I’m trying to do view a STO gameplay video and you will see how I want my ships to turn and work. Thanks All:shock:
Also does anyone have a basic black star style skybox without planets for free I can get? Looking all over internet with not much luck. Suggestions welcome!
How do I go about making a bubble shield for ships in my game? Some way to make object visible/invisible or something? Theres got to be a good trick.
For tilting you would basically be rotating on your z axis along with your y axis, but you wouldn’t be able to do it in world space, you would have to do it in local space.
Well can’t use local space since it rotates the world and not the object… also not sure where you were going with the w and s keys.:shock:
Also new problem… lol another! 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.
Everything is relative. No it doesn’t rotate the world, it actually just rotates the object according to it’s own coordinates rather than world coordinates. So, if you are moving forward, it’s the direction that the model is facing that is forward, not north or whatever. It comes in very handy. It sounds like you need some basic tutorials.
You can add any collider you want to your object, or you can use the mesh as a collider, but it’s more expensive.
Moving works fine now it seems but now I added a Ridgidbody to both ships and use is Kinematic, unchecked gravity, and set angular drag to zero for both ships. But now I have 999 actor errors saying “Actor::updateMassFromShapes: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.
Hmmm… I see what it means but not sure it really helps in this case. The object I have is a full object with many meshes in it. So instead of changing the individual meshes I simply added the ridged body to the full object. Do I add a box collider to each mesh segment or what?