- Home /
Gradual Acceleration?
Hello, and thank you in advance for your help I am making a game that uses lots of the plane mechanics But thr code provided to me only half works it has a constant speed either going up or down
can anyome help me getting a gravity-like feeling of an acceleration while pointing down and/or up(stalling)?
I like to use a velocity model. For a falling object, you can do:
velocity.y += gravity * Time.deltaTime;
Answer by darthbator · Sep 25, 2013 at 10:56 PM
You would want to do something like (this is a really lame example but hopefully you get the idea).
transform.Translate(transform.forward * speed * Time.deltaTime);
speed += Time.deltaTime * speedMod;
This way with each frame (or run of this code if you use a coroutine or other bounding factor) the speed that the object is moving at is increasing with each frame.
If you want to reduce the speed of motion you simple reduce the value of speed. Which can either be done gradually kind of like adding to it.
I would like to try this but before doing it i'm afraid that this will (hopefully) work in EVERY direction, while i'm looking for a way to simulate gravity (while going down) and stalling (when going up), would it be possible to implement in the code something that reads the Y axis and behave in that way? Sorry for the bother
Yes this will work with any float in the vector. I simply used forward as an example.
darthbator i hope you can help me once again with this.
here is the code i'm using right now
#pragma strict
var speed : float;
var speed$$anonymous$$od : float;
function Start () {
}
function Update () {
if(Input.GetButton("run"))
transform.Translate(transform.forward * speed * Time.deltaTime);
speed += Time.deltaTime * speed$$anonymous$$od;
}
I implemented the "run" input just to test the movement of it.
the problem with this is that there is no smooth transition from the initial speed to the upgraded one, it goes from 1 to 100 in one frame for some reason
while another problem is that i personally do not yet understand how Vector3 works at all, i cannot get it to work because it's supposed to go faster when facing down, but slower when reaching a certain point of height
can you help me with that?
Your answer
Follow this Question
Related Questions
How do I calibrate my games's pitch (0,0) position on android accelerometer? 0 Answers
UnitySteer - any way of determining when you've arrived at a node? 1 Answer
using cohesion but keeping minimum distance apart with unitysteer 0 Answers
Need Help for aeroplane scrip 1 Answer
Proximity Detection Code not working 2 Answers