- Home /
Moving an object in 3D Space ~ Complexity
Hello referring to my old question which seems to be unanswerable as the character controller and rigidbody don't work together. here . So I have changed my approach a bit, Q - How about a rigidbody in 3D space that can will be accelerated with a button lets say A and the player could control its movement on axis with the arrow keys.
And is there a possibility that I could add an object called 'head' make it the main object's child and move the head and the main object (sphere) will rotate and move towards it ?
Answer by MountDoomTeam · Feb 23, 2013 at 05:42 PM
Hello, well done for working on that question, it is by figuring out those 1st steps that you learn to understand unity very well, the worm game tutorial is quite good for learning character movement at some chapter in the tutorial. the worm game has a head, and some body segments that just follow weatherhead goes with smooth follow.
Here's the 1st movement script I did for unity it's for flying an aeroplane it's got some basics in it. I think the commented out code afterwards is perhaps the one from the worm game, it also has a fire button and you need an invisible GameObject in front of the player from where the bullets are spawned, although you could also just make them spawn at GameObject + certain distance. There is constant force, relative force, etc. Have a look on youtube for marble games? And also the worm game.
Good luck
var speed = 15.0;
var rotspd = 10.0 ;
var bullitPrefab : Transform;
function Update ()
{
if ( Input.GetKey("mouse 1") )
{constantForce.relativeForce = 15000 * Vector3.forward
;}
else
{constantForce.relativeForce = Vector3.zero;}
if(Input.GetButton("forwards"))
{
transform.eulerAngles.x += rotspd * Time.deltaTime * 7;
}
if(Input.GetButton("backwards"))
{
transform.eulerAngles.x += -rotspd * Time.deltaTime * 7;
}
if(Input.GetButton("left"))
{
transform.eulerAngles.y += -rotspd * Time.deltaTime * 7;
}
if(Input.GetButton("right"))
{
transform.eulerAngles.y += rotspd * Time.deltaTime * 7;
}
if(Input.GetButton("Fire1"))
{
var bullit = Instantiate(bullitPrefab, transform.Find("spawnPoint").transform.position, Quaternion.identity);
bullit.rigidbody.AddForce(transform.forward *8000);
}
}
/*var speed = 3.0;
var rotateSpeed = 32.0;
var bullitPrefab : Transform;
function Update ()
{
var controller : CharacterController=GetComponent(CharacterController);
//Rot
transform.Rotate(0, Input.GetAxis ("Horizontal") * rotateSpeed, 0);
//fwd bck
var forward = transform.TransformDirection(Vector3(0,0,1));
var curSpeed = speed * Input.GetAxis ("Vertical");
controller.SimpleMove(forward * curSpeed);
if(Input.GetButtonDown("Fire1"))
{
var bullit = Instantiate(bullitPrefab, transform.Find("spawnPoint").transform.position, Quaternion.identity);
bullit.rigidbody.AddForce(transform.forward *2000);
}
}
*/
Thank you for understanding the situation ;w; I really appreciate and the worm tutorial was my first tutorial for unity (tornadotwins rocks) but thing here is my object is in the space like real space out there and its going towards its goal and its gonna be for the android/ios the sphere will go forward (in deep the screen) and when the player tilt the phone it will move up/down left/right but still going deep with its own velocity
now I don't want to ask for code for iphone/android I will see that myself but first I have to get the correct approach to it and my player must be a rigidbody because in further gameplay depends upon collision and stuff :/
If I could P$$anonymous$$, then I will be able to explain more accurately how I need it to be, its too difficult the camera also Fs up with rigidbody and addforce, I couldn't even start with my game unless I have the basic player script set up
Your answer
Follow this Question
Related Questions
Player on moving object doesn't follow it Unity 5 0 Answers
Attach a Player to a moving GameObject 0 Answers
Parent Object 0 Answers
simple collision not working 1 Answer
Object won't collide with Player unless Player is moving 1 Answer