x


Wall Pushing an Object

Hello, I'm trying to make a wall that push an object when it hits the wall and when the wall its yellow painted.

I already made a wall that when I paint the wall with the blue color, it pull an object, but I don't know how to make pushing it when its touching.

Here's the Yellow Wall Script (it works):

using UnityEngine;   
using System.Collections;

public class NewBehaviourScript : MonoBehaviour {


public Rigidbody bola; 
public float speed = 2;


public void Update(){

}
public void OnCollisionEnter(Collision collision) 
{ 
 if (collision.gameObject.tag == ("bola")){   
 if (renderer.material.color==Color.yellow){


      Debug.Log("tocou");
  bola.transform.Translate(Vector3.forward* speed * Time.deltaTime);
        }
    }     
  } 
 }
more ▼

asked Apr 01 '11 at 11:13 PM

viktor gravatar image

viktor
2 1 1 1

(comments are locked)
10|3000 characters needed characters left

2 answers: sort voted first

I think that you need to apply a force to the rigidbody to simulate a "real" push, if you use transform the push is not going to be realistic, and it will be more similar to an animation.

To apply a force to a rigidbody in the Z axis (in c# for example):

Vector3 myForce = new Vector3(0.0f, 0.0f, 10.0f);
bola.AddForce(myForce);

The vector force depends on what you want to do :)

more ▼

answered Apr 02 '11 at 12:51 AM

rodridkv gravatar image

rodridkv
25 3 5 10

Hmm... It didn't work... weird, the Debug.Log it's showing perfectly! Thank you for helping! ;)

Apr 02 '11 at 02:27 PM viktor
(comments are locked)
10|3000 characters needed characters left

I used this sugestion, but in game, the object only move in Z. The game have many wall's, and the wall push the object. i want the wall increase the distance between "bola" and the wall.

thx

more ▼

answered Apr 05 '11 at 12:37 PM

Pedro 3 gravatar image

Pedro 3
1

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x1278
x576
x507
x498
x70

asked: Apr 01 '11 at 11:13 PM

Seen: 896 times

Last Updated: Apr 01 '11 at 11:13 PM