x


Controlling a variable of type Vector 3

for example we have a variable v1: Vector3;

when a collision happens we want to increase the vector3's x by 100 ! is there a way to do that ? thanks

more ▼

asked Sep 26 '10 at 08:48 AM

anthony gravatar image

anthony
15 3 3 6

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

1 answer: sort voted first

You can modify the x/y/z of a Vector3 as follows.

var vectorOne : Vector3;
vectorOne.x += 100;

If you want it to happen when objects collide, you can use OnCollisionEnter or OnTriggerEnter, depending on the rest of your setup.

more ▼

answered Sep 26 '10 at 08:54 AM

Marowi gravatar image

Marowi
4.9k 4 14 53

thanks that is what i was searching for!

Sep 26 '10 at 09:22 AM anthony

Comment back on my answer if you have any troubles with the implementation and I'll help out where I can. :)

Sep 26 '10 at 09:35 AM Marowi

i think i have a problem!

if(collisionInfo.gameObject.tag == "player1") { velocity.x = velocity.x* 10000;

}

if(collisionInfo.gameObject.tag == "player2") { velocity.x = velocity.x* -10000;

}

but the velocity is still not changing! In the inspector it is still 0! do you have any idea why?

Sep 26 '10 at 09:44 AM anthony

Multiplying 0 by 10000 will result in 0! Maybe add a "Debug.Log()" line in there to be sure that your ifchecks are working?

Sep 26 '10 at 09:55 AM Marowi

you were right the if was not working but im not sure what im doing wrong...

function OnTriggerEnter(collisionInfo : Collider) { if(collisionInfo.gameObject.tag == "player1") { print("HELLO"); velocity.x = (velocity.x+1)* -100;

}

if(collisionInfo.gameObject.tag == "player2") { print("HELLO"); velocity.x = (velocity.x+1)* 100;

}

}

the hello is not showing! although im sure my script is right! do u have any idea?

Sep 26 '10 at 02:14 PM anthony
(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:

x821

asked: Sep 26 '10 at 08:48 AM

Seen: 907 times

Last Updated: Sep 26 '10 at 08:48 AM