So managed to code in the bounce but haven't been able to figure out how to make the bounces smaller and eventually make it stop.Any suggestions?
public Vector3 velOriginal;
public float E;
private Vector3 vel;
private Vector3 pos;
private Vector3 gravity = new Vector3(0.0f, -9.81f, 0.0f);
//public bool changeGravity = true;
// Start is called before the first frame update
void Start()
{
pos = this.transform.position;
vel = velOriginal;
}
// Update is called once per frame
void Update()
{
pos = pos vel * Time.deltaTime;
vel = vel gravity * Time.deltaTime;
this.transform.position = pos;
if (this.transform.position.y < 0f)
{
pos.y = 0.52f;
this.vel = velOriginal * E;
}
}
CodePudding user response:
Why without the physics engine? Without it you are going to need to specify which are the geometries colliding against each other to perform the geometric calculations soas to check if they are colliding.
Without the physics engine I think you mean without using a rigidbody and avoiding physics for the movemement specifically. In that case integrating the speed to obtain the pos and integration the accel to obtain the speed are in the update is fine, then I would invert the Y axis speed direction in
the OncollisionEnter().
So,
void Update()
{
pos = vel * Time.deltaTime;
vel = gravity * Time.deltaTime;
}
And:
OnCollisionEnter(Collision collision) {
if (isCollidingSurface) { //check somehow if is the collision of interest
vel.y = -Mathf.Abs(vel.y)
}
}
For this you will need the OnCollisionEnter and a rigidBody in one of the gameObjects for the OnCollisionEnter to take place I think, which means using the physics system. However it wouldnot mean that the gamoObject is moved with the rigidbody physics, with forces etc, which is what I think you are trying to avoid.
