Moving object with transform.position ignore other objects even if they collided

Please give me help:-|

The Problem is Moving Sphere with changing “transform.position” ignore other objects even if they collided.

And now, I must use “transform.position” for some reason.

I’m coding my first game project with Unity, and I want Sphere to move along with bezier curving.

To realize this, I solved by changing gradually Sphere’s “transform.position” value with bezier curving logic.
And it successfully worked.

But, there is a big problem in this code… :frowning:

Although, collision can be detected between moving Sphere and other game objects in OnCollisionEnter,
the Sphere ignore other object and pass through destination as if there aren’t any other objects in the orbit…

For Example, I coded like below.This script is attached to Sphere.

In this code, I guessed if Sphere ignore other object , AddForce to Sphere at the time they collide can be solution.
But it doesn’t work also.

function Update () {

   var additional = 0.01;/
   // If gameObject goes down, it surely collide with other Object with tag "Barrier"
   gameObject.transform.position = Vector3(gameObject.transform.position.x, gameObject.transform.position.y - additional, gameObject.transform.position.z);
}

function OnCollisionEnter(collision : Collision) {
   if (collision.collider.tag	== "Barrier") {
	    rigidbody.AddForce(Vector3.up * 100);//This does't work also
   }
}

I tried to solve this problem for two days, but I could’t.

If you give me help, I’ll be so glad…

Thanks.

The physics engine handles collisions and such during a secret physics step that you don’t program. To use it, make sure the object has a rigidbody (looks like yours does) and set rigidbody.velocity. The engine uses velocity to move, bounce and so on.

If you move with tranform.Translate or transform =, it’s like you are repositioning or teleporting the object. The next physics step says “hey, wasn’t this speed 0 object over there last time? Now it’s partially inside this goat. Oh, well.”

A cheap way to set velocity, but also follow a curve is to “aim at” a spot just ahead of you on the curve. Something like:

Vector3 pos2 = next spot on the curve
// NOTE: p2-pos is direction to next spot from old spot
//      normalized*speed is standard way to turn direction into constant speed
Vector3 spd = (pos2-pos).normalized * speed
rigidbody.velocity = spd;

It’s a little like guiding a dog around a racetrack with a moving bunny (the dog is the object and the bunny is the “next position”.) You won’t guide the dog exactly where you want it, but close enough. You have to move the “next point” and the dog at the right speeds so the dog doesn’t overshoot and turn around; and also slow enough so the dog doesn’t cut across the track. So, say you use time to pick next spot. Just have to tweak the object’s speed.

Oh, It successfully worked, my Sphere bounce with other objects !!!

Thank you so much such for giving me such a excellent answer,
Your example is very easy fo me to understand…
And sorry to be a just a beginner but, " The engine uses velocity to move, bounce and so on." is a great tip for me.

Thanks you Mr.Owen and Mr.aldonaletto :slight_smile:

I have the same problem in my game but i dont want to use a rigidbody. is there any way to use the transform.position and still collide with stuff?