- Home /
Player bouncing off issue
Hi. I'm doing space shooter game and I have one issue. When I'm flying into my planet(big sphere with sphere collider) for longer then one hit(my cube whitch represends my ship just bounce for a while on sphere) and i stop presing control button my ship flyes away from planet. I don't know what to do and how i can prevent it. Any help? I'm attaching my scripts from planet and player. Player(has collider and ridgitbody) :
using UnityEngine;
using System.Collections;
public class GraczS : MonoBehaviour {
public float speed= 10;
// Update is called once per frame
void Update () {
float front_w = Input.GetAxis("Vertical")* speed * Time.deltaTime;
transform.Translate(Vector3.forward * front_w);
float upanddown = Input.GetAxis("UpandDown") * speed * Time.deltaTime;
transform.Translate(Vector3.up * upanddown );
float side_w = Input.GetAxis("Horizontal")* speed * Time.deltaTime;
transform.Translate(Vector3.right * side_w);
}
}
And planet(Only collider)
using UnityEngine;
using System.Collections;
public class Ziemia : MonoBehaviour {
public float predkoscObrotu ;
// Update is called once per frame
void Update () {
transform.Rotate(Vector3.up * predkoscObrotu * Time.deltaTime);
}
}
Please format your code properly.
Does your rigidbody toggle gravity on/off depending on whether they are in space/on planet?
Gravity is turned off. In project every movement is controlled by scripts. Now code is better? Change something? predkoscobrotu in 2. code means rotatespeed
Are your movement controls, while on the planet, using Vector3.up or something like that? Are they, at contact, stopping all forces from rigidbody?
I don't think so. If I cant understand You properly( sorry I don't know English on advanced level) nothing changes on collision. I'm just using default options in my scene i have only sphere with planet script abd collider and player with ridgitbody, my player script camera and mouselook script from assets attached to ship so i can rotate it.
Thank you so much. Please write it as the answer so I can approve it and give you thumb up! Really big: Thank you.
Answer by getyour411 · Mar 22, 2014 at 09:08 PM
I don't use Rigidbodes often, but one that's in motion, upon striking something else, will often bounce/react which sounds like what you are experiencing when you say "ship flys away from planet". I think you need a way to force/stop on contact with Collider to stop that. Something like
rigidbody.velocity = Vector3.zero;
Edit: converted to Answer