|
I'm having trouble moving a basic rigid body object. Simple I know. But I just can't seem to get it to work. All I want to do is move it by a basic 3D vector. Does anyone have any tips how I can do it? I'm rather new to unity.
(comments are locked)
|
|
You can use
Where offset is the vector direction you want to move in Yeh see this is the kinda thing i've been trying but something isn't working. Heres the code i'm using currently: function Update () { var acceleration = iPhoneInput.acceleration; var offset : Vector3 = Vector3(acceleration.y,acceleration.x,0); rigidbody.MovePosition(rigidbody.position + offset); } I'm using the iPhone as a remote and the acceleration seems to have no real baring on the way the object moves. I'm sure i'm doing something wrong....
Jul 04 '10 at 11:40 AM
ROM
@Strange, you should generally put code back into your original Question, and you can format it with the "1010101" button. Fixed. (But at least you used the comment field, and didn't create a whole new Answer like people sometimes do. :)
Jul 04 '10 at 01:31 PM
Cyclops
In that case, i would have thought adding a force would be more appropriate
Jul 04 '10 at 02:20 PM
Mike 3
Yeah, if you're using RigidBody, you ought to use AddForce() or AddRelativeForce() when moving them anyway. Moving the transform leads to the dark side.
Jul 04 '10 at 03:22 PM
Novodantis 1
I thought it would be rigidbody.position * offset if rigidbody.position is a Vector3
Jul 04 '10 at 07:44 PM
fireDude67
(comments are locked)
|
|
There are multiple ways to move objects. Through rigidbody force (the physics system, through Linear Interpolation (Lerp for short), and also through the transform (which I believe uses Matrices Transforming, but I'm not a math guru). I've written a detailed guide on how to move through rigidbody forces on my studio's website http://wiki.certainlogicstudios.com/ There is also the CharacterController class, which uses one of the above listed methods. I'm not sure which one. The class itself has something of a bad reputation. I think it is expensive to use, and is only meant to be used on 1 character in your game at a time, like the main player in a platformer (but not the enemies). iTween does take a lot of the mystery out of movement (unless you wonder how they are performing their black magic, then it's even more mysterious!). I don't have a lot of experience with it, so someone please correct me if I am wrong, but I don't believe you can use the physics system with it. So, it really depends on the kind of game you are making, and how you want your objects to react. Edit: Make sure you do your physics updates inside of FixedUpdate, which fires at a constant interval. Update fires once per frame, and is therefore dependent on the frames per second of the computer running the game. You may experience poor physics simulations because of that.
(comments are locked)
|
|
Check out iTween, its an epic animation script for unity, beats the hell out of the default unity animator. there is documentation and video tutorials on the site: http://itween.pixelplacement.com/ hope this helps
(comments are locked)
|

@Strange - what are some of the other properties of the Rigidbody? Mass, gravity, etc? You can re-edit your Answer to update it.