|
Hello, I have recently begun making a space simulator game, and have had trouble making a character controller that can be used by both the AI and the player. My previous controllers stored the target angle in a quaternion where the ship would gradually turn towards it until the angles match (For players this value would be adjusted using Input.GetAxis). However, I had difficulty implementing angular acceleration as well as limiting the maximum turning rate of the ship. How would I go about making a controller with these features in JavaScript? edit: Here is my code that works properly, but i have had trouble adapting it for the AI. How could I make it work while keeping the same turning speed? Any suggestions are welcome.
(comments are locked)
|
|
Quaternion.LookRotation is returning your "End-goal" rotation and then we're multiplying that by turn speed. On the other hand the player is giving 3 values between -1 & +1 which we multiply by turnspeed. Off the top of my head, if you: This will give you a Vector3 with all of it's values between -1 & +1 so you can muliply and use in transform.Rotate. Thanks Note: You can also divide temp[i] / turnspeed just before we clamp it. This does nothing if temp[i] > turnspeed but otherwise it means the AI slows down enough to stop exactly on the target angle as opposed to continuously overshooting and "vibrating" back and forth.
Jul 21 '12 at 08:38 PM
Muuskii
Brilliant, it works! :) There's also the matter of giving a feeling of weight to the ships again, but I'll mark this as answered and tackle it later. Thanks for the great help :)
Jul 21 '12 at 09:26 PM
Adamant356
Glad I could be of help.
Jul 22 '12 at 12:47 AM
Muuskii
(comments are locked)
|
btw: AISetsTargetAngle can be inside another script attached to your ship. . . or any other game object for that matter! Great for having different piloting styles.
Jul 21 '12 at 06:32 PM
Muuskii
Thanks for the reply, the code looks much cleaner now :) Unfortunately things still aren't right: I used the inertiaFactor variable to give a feeling of mass to the ship (0 is sluggish, 100 is frictionless), but now that part of the code doesn't work correctly anymore. I'd rather do away with it entirely and use a new system with variables for angular acceleration and deceleration but can't get my head around it. Also, how would I go about finding the target angle for the AI? I tried Quaternion.LookRotation but the results aren't right. Anyway, thanks for your patience :)
Jul 21 '12 at 07:28 PM
Adamant356
(comments are locked)
|
