- Home /
Trying to set velocity to a gameobject without a rigid body
public void Update (float deltaTime) {
//not really sure what the syntax is to set the velocity
splash.velocity.Set(0, 0, 0);
}
if you want to set velocity, you need to make your own movement based functionality, since you don't want velocity. You could find the average velocity given your own speeds, but setting it won't really do good unless you have created the implementation similar that of rigidbody component, but more simpler.
Answer by Loius · Feb 10, 2013 at 01:58 AM
Your syntax is whack. You should work your way through at least one official Unity tutorial, it'll answer most basic questions.
public Vector3 velocity;
public void Update() {
transform.position += velocity * Time.deltaTime;
}
This will teleport the object from point to point, which will actually put it inside other objects if they're in the way. There is a HUGE amount of discussion on this topic already, please search if you need to solve that particular issue.
I would use this same approach but in the fixedUpdate and using fixedDeltaTime ins$$anonymous$$d of deltaTime, that way is similar to the RigidBody approach in terms of update order asi in this link https://docs.unity3d.com/$$anonymous$$anual/ExecutionOrder.html
Answer by Zels · Feb 10, 2013 at 01:33 AM
So how would I go about starting that?
So if you want an object to move in any direction you would have to have a direction for the x, y, and a z if 3d, as well as a speed for that object. So if you wanted it to move you would need something like this.
new Vector3 (target.position.x (multiplied by) speed, target.position.y (multiplied by) speed, 0f); for a 2d game. if its 3d you'd want a z axis as well.
for the speed you can have it set to private if you wanted to initialize it in code or make it public and set it in the inspector.
your target would be an object in the game you want the projectile to move to. or you could just have it as a number if there isn't a target.
Hope this helps!
Answer by Zels · Feb 10, 2013 at 01:33 AM
How would I got about doing that?
This isn't an answer (and neither is the other copy of it).
Your answer
Follow this Question
Related Questions
How to get local axis from characterController.velocity 1 Answer
How to make a gamebject wiggle slowly as it moves forward ? 1 Answer
I am trying to code a .velocity but i dont get the option of choosing it. 1 Answer
How I can change the speed of an object with the speed of sound so they are evenly matched? 2 Answers