Rocket Landing
Rocket landing controller, rocket is coming towards earth due to gravity its moving down, so i want to give thrust to rocket in such a way its slow down the falling the velocity(-ve velocity in y direction ) of rocket not make it to move rocket upward, but if i pressed the thrust button for longer time its should slowly move upwards....here is my code that i am using.
private Rigidbody rg;
public float thrustvalue;
public float speed;
public float constantforce;
public bool iscollided=true;
// Use this for initialization
void Start () {
rg=GetComponent<Rigidbody>();
Physics.gravity=new Vector3(0,-15,0);
}
// Update is called once per frame
void FixedUpdate() {
if(iscollided){
rg.AddRelativeForce(0,constantforce,0);
}
if(Input.GetKeyDown(KeyCode.Space)){
rg.AddForce(transform.up*thrustvalue);
//rg.AddForceAtPosition(transform.up*thrustvalue);
}
if(Input.GetKey(KeyCode.LeftArrow)){
transform.Rotate(0,0, -Input.GetAxis("Horizontal")*speed*Time.deltaTime);
}
if(Input.GetKeyDown(KeyCode.RightArrow)){
transform.Rotate(0,0, Input.GetAxis("Horizontal")*speed*Time.deltaTime);
}
}
void OnCollisionEnter(Collision collisionInfo)
{
iscollided=false;
}
Ins$$anonymous$$d of applying force on key down event try applying following way :
if (Input.Get$$anonymous$$ey($$anonymous$$eyCode.Space))
{
rg.AddForce(transform.up*thrustvalue,Force$$anonymous$$ode.Force);
}
Answer by Vincent1236 · Feb 20, 2018 at 11:34 AM
What is currently happening/not happening? There could be various things going wrong. Supply some more information please.
Your answer
![](https://koobas.hobune.stream/wayback/20220612153010im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Figuring out what the acceleration will be before applying force to RigidBody2D 0 Answers
How to set rigidbody velocity and angularVelocity to Vector3.zero over time? 1 Answer
How do I make a rocket? 2 Answers
Sphere with AddForce or Velocity not moving 1 Answer
Custom touch control stops abruptly! 0 Answers