Before updating to Windows 10 you may need to return your Pro license. More information here

Change a property based on angle?

In my game, the player can jump through hoops which adds to the player's current velocity. On contact, each hoop passes a Vector3 to the player script, however, if I tilt the hoop to create angled jumps, the Vector3 passed does not change, so the player is thrown in world space. Is there any way to change the Vector3 passed from the hoop depending on its angle so that the angle affects the direction of the jump? Thanks!

Here's the hoop script.

 var gameScript : GameController;
 var velocityToAdd = Vector3(0,10,0);
 var localRotation : Vector3;
 function Start (){
     gameScript = GameObject.Find("Player").GetComponent(GameController);
 function OnTriggerEnter (myTrigger : Collider) {
     if(myTrigger.gameObject.name == "Player"){
more ▼

asked Oct 05, 2011 at 08:04 PM

avatar image

50 23 18 21

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

1 answer: sort voted first

I suggest you to change the idea a little: define a float speed in the hoop script, then pass the velocity vector as transform.up multiplied by this speed. It makes things a lot easier, since you know that the speed may have different intensities, but will always point the up side of each hoop - just tilt each hoop to the orientation you want:

var velocityToAdd: float = 10;


function OnTriggerEnter (myTrigger : Collider) { if(myTrigger.gameObject.name == "Player"){ gameScript.addVelocity(transform.up * velocityToAdd); Destroy(gameObject); } }

more ▼

answered Oct 05, 2011 at 08:50 PM

avatar image

61.6k 57 213 361

Thats perfect, much simpler, thanks!

Oct 05, 2011 at 08:59 PM ataxk
(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



Answers and Comments



asked: Oct 05, 2011 at 08:04 PM

Seen: 911 times

Last Updated: Oct 05, 2011 at 08:59 PM