- Home /
Translation of an object
I'm trying to move a character upwards by a set amount when it touches a jump-pad. Here is the code so far:
var velocity : Vector3; var jumpSpeed : float = 50; var maximumSpeed : float = 30; var minimumSpeed : float = 10; private var controller : CharacterController; function Awake(){ controller = GetComponent(CharacterController); } function Update(){ controller.SimpleMove(velocity); } function OnControllerColliderHit (hit : ControllerColliderHit){
if (hit.gameObject.name == "Jump") { transform.Translate(Vector3(0,jumpSpeed,0) * Time.deltaTime); }
Now, the problem is that this moves the character upwars (y-axis) by a certain amount in the space of 1 frame. How do I change this so it is over a longer time period?
Just a lil thing.... If you make the jump pad actually translate up on collision, the player does fly up in the air... It works exactly like a jump pad... Lol.
Answer by Joshua · Apr 03, 2011 at 01:08 PM
At the top, add
var time : float = 1.0;
and in the part where it says Time.deltaTime, behind that but before the ) add
* time
now you can, in the editor, change the time from one frame to what ever you'd like.
So it reads transform.Translate(Vector3(0,jumpSpeed,0) * Time.deltaTime*time);, yes?
Once you've done what I said go to where you have this script attached to, go to the inspector view and now there is a variable called time which you can change.
No, that doesn't help, even when I set it to much bigger values.
Answer by Owen-Reynolds · Apr 03, 2011 at 04:43 PM
I think Joshua is assuming the jump pad is TALL -- as tall as how far you jump. Every frame you are in it, you go up, like an anti-grav elevator.
If you really have a JUMP pad, you could set velocity to some trial-and-error number (10 is about 1G, so 20-40 is a good start.) Depending how your movement works, rigidbody.velocity.y=30;
or velocity.y=30;
replace the transform.Translate part with rigidbody.velocity.y=jumpspeed; and tweak that.
controller.Simple$$anonymous$$ove(velocity);
is moving the object. That means the velocity
variable controls the speed it moves.