- Home /
Question by
ThePixelatedSword · Jul 23, 2017 at 07:31 AM ·
movementtransform3dspace
Help needed moving this gameobject
I'm currently developing a game based mainly on physics. I need help moving a gameobject via an attached thruster. The thruster won't just be moving forward. I have tried moving it using a rigidbody but that messes with other functions. I would really appreciated if you could help. My current thruster script is this.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[RequireComponent(typeof(Rigidbody))]
public class Thruster : MonoBehaviour {
public float fuelEffiecent;
public float output;
public KeyCode thrustButton;
bool outOfFuel;
Rigidbody rig;
void Start () {
rig = GetComponentInParent<Rigidbody>();
}
void Update () {
Core core = GetComponentInParent<Core> ();
if (Input.GetKey (thrustButton) && core.fuel >= fuelEffiecent) {
core.fuel = core.fuel - fuelEffiecent;
rig.AddForce(Vector3.forward * output);
}
if (Input.GetKeyUp (thrustButton) || core.fuel < fuelEffiecent && outOfFuel == false) {
core.speed = core.speed - output;
outOfFuel = true;
}
if (Input.GetKeyUp (thrustButton)) {
core.speed = core.speed - output;
}
}
}
This is still using the rigidbody code.
Comment
Your answer
Follow this Question
Related Questions
Move object towards mouse in full 3D space 2 Answers
Moving player in direciton camera is facing 1 Answer
Manipulating cursor direction in 3D space 0 Answers
a better movement code C# 3 Answers
Move Object to location of Trigger? 1 Answer