|
Hi I have a script on an object to make it bounce on click and I have added another script to make the ball roll when the screen is tilted, however since adding the second script my ball dosent bounce as well now. Any ideas? do I have to put this all in one script?? I am using JS as I am a more confident java programmer. Thanks
(comments are locked)
|
|
Ok...transform.Translate invalidates the rigidbody.AddForce. Merging these two scripts wouldn't help. Either use AddForce for the tilting or split the scripts even more: Parent the ball to an empty, attach the bounce script to the ball and the tilt script to the empty. Hi, ok this kind of makes sense, I am very much a beginner at this so still learning my way around. When you say parent the ball to an empty, whats an empty?? sorry for my ignorance. Thanks
Jul 19 '12 at 06:08 PM
hanimalP
An empty is the simplest gameobject in Unity. It has no components whatsoever, just a transform.
Jul 19 '12 at 06:14 PM
Piflik
Ok great, Thank you for this. I will give it a try :)
Jul 19 '12 at 06:15 PM
hanimalP
Ok, this option didn't work :( how do I add force for the tilting??
Jul 19 '12 at 06:43 PM
hanimalP
(comments are locked)
|
|
opps, scripts would help! This is the tilt script and the bounce script Thanks
(comments are locked)
|
|
Yes put it in one script. If you have two independend Update functions, you can never know which on is called first. So the two position changes may or may not combine as you wish, and that each frame. There are ways to provide that via Script Execution Order Settings, but I would handle the movement of one object in one Script. Otherwise you would have a lot more work to have it consistently and the possibility of hard to find errors is reduced. For more info we gotta take a look at your scripts. Ah I see the problem you mix rigidbody.AddForce and transform.Translate. So the physics engines transformations conflict with yours added by hand- You can try to do the rigidbody operations in FixedUpdate() instead of Update() and try if this helps. But a rule of thumb would be to either use forces and physics or translate by hand to move an object and avoid mixing both mechanics. It can work, but a lot has to be considered. i.E. you can calculate the bounce too and apply it to transform. Or you can move the ball left right forward backward by forces or velocitys.
Jul 19 '12 at 03:01 PM
Nightwatch
(comments are locked)
|

It would help, if you'd posted the scripts...probably you are overwriting the bounce with the roll in your second script, but how exactly to prevent this I cannot say without seeing the scripts...
as Piflik said it would have helped to post the scripts and he is most likely right in why this is causing a problem however this can be fixed, make sure in the bounce script you are ONLY changing the vertical (probably y) position of the ball and in the roll script you are ONLY changing the horizontal(x or z) component of the ball, that way neither of the scripts will effect the other script. hope that helps, Scribe