mado
New vMember
Posts: 4
|
Post by mado on Jun 14, 2018 14:57:44 GMT
Sorry, but I will use Google translation.
Purpose: 1.Operation character enters a specific area 2.In accordance with the laws of physics, under the influence of the right towards the designated direction(Ignore previous accelerations)
Current status: 1.Operation character enters a specific area 2.Travel distance decreases on the ground & Moving direction is not ideal(Probably the immediately preceding acceleration is indicated)
Code:(Cube with IsTrigger turned on) public void OnTriggerEnter(Collider other) { // Initialize previous acceleration other.GetComponent<Rigidbody>().velocity = Vector3.zero; // I always want to gain strength (0, 10, 10) other.GetComponent<Rigidbody>().AddForce(new Vector3(0, 10, 10), ForceMode.VelocityChange); }
Environment: Unity 2017.4.4f1 (64-bit) Third Person Controller - Basic Locomotion FREE 1.0c Operation character:3rd Person Controller -> Person Controller -> Create New Character
Comment: What is the shortage? Answer (or URL to commentary etc.) is necessary...
|
|
|
Post by Invector on Jun 14, 2018 22:17:06 GMT
So... basically you want to addforce to the rigidbody once it enters a trigger? The approach is almost correct, but you need to use OnTriggerStay instead of OnTriggerEnter, otherwise it will apply the force for only 1 frame or so
|
|
mado
New vMember
Posts: 4
|
Post by mado on Jun 15, 2018 8:59:34 GMT
So... basically you want to addforce to the rigidbody once it enters a trigger? The approach is almost correct, but you need to use OnTriggerStay instead of OnTriggerEnter, otherwise it will apply the force for only 1 frame or so I tried the means taught, but it was not ideal. Inspection results movie: Overall flow 1. Confirmation of each object 2. Test on "OnTriggerEnter" 3. Test on "OnTriggerStay" I think that I will instantly fly characters entering the explosion range with a fixed angle and fixed force. (Therefore, ForceMode is VelocityChange) When I tried OnTriggerEnter, Sqhere made an ideal movement! However, unfortunately the operation character seems to maintain the previous acceleration. When OnTriggerStay is tried, Sqhere and operation characters follow a fixed "direction". However, the longer the time in the Trigger, the stronger the power. (I'd like the applied force to be instantaneous and constant) Like Sqhere on OnTriggerEnter, Regardless of just before accelerating, what is necessary to give a fixed force to the operating character?
|
|
mado
New vMember
Posts: 4
|
Post by mado on Jun 17, 2018 14:09:21 GMT
・FlySphere ComparisonObject
・vThirdPersonController Operation character
・SphereExplosion(script:SphereExplosion) Add power to objects in the trigger (It occurs in several seconds after execution)
・SphereExplosion velocity = new Vector3(-20, 10, 0) to FlySphere & vThirdPersonController
●Conclusion FlySphere will work as instructed(This is what I seek for the operating character!) Operation character moves directly above(I am not asking for this)
●Question If you try OnTriggerStay under the same conditions, you may jump in the direction you instructed, but Sometimes it fly in other directions. (Just above, the front of the character etc.) Therefore, I anticipate that vThirdPersonController is overwriting its own acceleration. Is there a way to avoid overwriting?
|
|
mado
New vMember
Posts: 4
|
Post by mado on Jun 18, 2018 21:21:17 GMT
Results when using OnTriggerStay
Most of the settings are common with previous videos.
・change point OnTriggerEnter -> OnTriggerStay
・Character Ideal movement(〇× is video editing, it has no effect on unity) Ideal -> 〇 No Ideal -> ×
・Result by OnTriggerStay call count 1 call : The percentage that is not ideal is 100%! 2 call more : There are times when it is either good or bad.
I think that the problem is not solved for both OnTriggerEnter and OnTriggerStay.
|
|