- Home /
Object acceleration
Hi, i have a object that is moving, but i want it to speed up. Can i be done without using Rigidbody?!
var objectSpeed:float = 1;
var maxSpeed:float = 100;
var Acceleration:float = 5;
function Update () {
transform.position.z = -15;
transform.Translate(Vector3.up * objectSpeed * Acceleration * Time.deltaTime);
}
Answer by THEpancakes · Oct 18, 2012 at 07:55 PM
Just call an increment on your acceleration variable every time you run the Update() function, so long as the acceleration variable is smaller than your maxSpeed variable.
Here's a simple script that will implement acceleration:
var acceleration : float;
var maxSpeed : float;
function Update() {
transform.Translate(0, acceleration * Time.deltaTime, 0);
if (acceleration < maxSpeed) {
acceleration += 1;
}
}
@THEpancakes can you tell me how to add this into my code
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Vehicle$$anonymous$$ovement : $$anonymous$$onoBehaviour
{
public float speed = 10;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
transform.Translate(new Vector3(0, 0, 1) * Time.deltaTime * speed);
}
}
i cant figure it out
Answer by RadhaUnity3d · Apr 12, 2013 at 03:06 PM
can any help me? Object Bounce slightly .. i used rigibody.instead of i want to move smoothly ... here is the code
using UnityEngine; using System.Collections;
public class Cubemovewall : MonoBehaviour {
// Use this for initialization
public float speed = 15.0F;
//public float rotationSpeed =100.0f;
public float hormin=-5.8f;
public float hormax=5.8f;
public float playerspeed=3.0f;
void Start () {
}
// Update is called once per frame
void Update () {
Vector3 dir = Vector3.zero;
// dir.x = Input.acceleration.x;
//dir.y=-Input.acceleration.x;
// dir.y = Input.acceleration.y;
dir.x = -Input.acceleration.y;
if (dir.sqrMagnitude > 1)
dir.Normalize();
dir *= Time.deltaTime;
transform.Translate(dir * speed);
}
}
If you want to ask a question, why have you posted an answer?
I'm just wondering who approved this post...
Your answer
![](https://koobas.hobune.stream/wayback/20220613082553im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Importing obj file with textures 5 Answers
getting the direction of object 1 Answer
Emmiter in time intervals 1 Answer
swapping out an object on collision 2 Answers
Problem with Object collision 1 Answer