- Home /
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"){
gameScript.addVelocity(velocityToAdd);
Destroy(gameObject);
}
}
Answer by aldonaletto · Oct 05, 2011 at 08:50 PM
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); } }
Your answer
Follow this Question
Related Questions
Set rotation based on 1,1,1 style vector? How to convert vector3 to quaternion? 1 Answer
Rotation from another object 1 Answer
Trying to get the angle of a camera object based on players forward, is not distance independent 0 Answers
'Rotating' a vector to have 1 axis = 0 1 Answer
Quick Angles Question 2 Answers