I'm using LeanTween engine and all was going well until I tried this:
LeanTween.moveY (menuPanel, 1200f, 0.5f)
.setEase (LeanTweenType.easeInOutBack);
The goal is to have the menu panel move down slightly before shooting up out of the screen. The easeInOutBack seemed the correct type (based on Easing Cheatsheet).
menuPanel is a GameObject UI Panel of which I declare as public and assign in the inspector.
Instead it goes a little crazy, bouncing up and down sporadically whilst moving a bit.
Has anyone observed this behaviour before, know what I'm doing wrong?
I know this is an old question, but just in case anyone else is having similar problems - you'll need to disable the Rigidbody attached to the game object you're tweening to avoid getting unpredictable behaviour in your raycast.
Related
I'm trying to make a sticky grenade by disabling its rigidbody upon collision, using OnCollisionEnter(). However, OnCollisionEnter() fires when there is clearly no collision happening, as you can see in this image : https://imgur.com/w9KMEff. This causes my grenade to stick in the air. I suspect this is due to a lack of synchronization between physics loop & rendering loop. Also, my standard "non-sticky" grenade uses the same model & is working finely.
I already tried the following :
Verify that there are no other colliders which could cause my grenade
to "stick in the air"
Use OnTriggerEnter() instead. The result is a little better but the problem is that it is fired too late, only once the grenade is inside an obstacle or an enemy.
Add rigidbody & continuous collision detection to all objects
Tweak PhysicsManager.DefaultContactOffset from 0.01 to 0.001, as suggested by Eliasar
Switch from "PCM" to "Legacy Contacts Generation"
None of these worked so I'm feeling a little desperate. Thanks in advance for your help !
Code I use to stick the grenade upon collision :
void OnCollisionEnter(Collision c) {
rigidbody.isKinematic = true;
transform.parent = c.transform;
}
PhysicsManager.DefaultContactOffset might be set too high for your object scale
According to this Unity forum post, your physics margin might be too high if your objects' scales are too small. OnCollisionEnter will fire during a Physics tick and may update your grenade's position a frame sooner than you're expecting. That would explain why it would stick outside the contact point, whereas OnTriggerEnter would process 1 frame later.
Unity post in text form
Max_van_Hell, Jun 1, 2017
oh god yeah Baby, I finally found the issue!
Appearantly the PhysicsManager.DefaultContactOffset was too high for my scale. The Default contact Offset was about 0.02 and with virtual objects which are around 10cm it yields a HUGE error margin obviously.
That never was a Problem for me, since in most graphics or game projects the scale of the objects is actually much larger so that such a contact Offset does not have a huge influence.
However, since this is a HoloLens Project and I am working with virtual objects which are around 10cm - 100cm the contact offset is more sensible.
Anyway, thank you much for your help!
cheers,
Hi guys i was wondering how to create a shape adjustment with two objects which specifically could be described as the independent cells, one of which is static, and the second one is dynamic and surrounded by "plasma". The movement of the active object must be controllable by the user (WSAD). Collision of the active object with the static one causes the static object to be swallen, though doesn't change it's position stays in place all the time. As the active object moves, passes the swallen object and troughts it out.
See the image below:
Player character
When it comes close enough to pink enemy it's starting to swallow it (surround by yellow thing)
Pink enemy is completely sourrounded when red circle is in the centre of both.
When it leaves enemy it takes off the yellow thing
I was wondering what is the simplest way to do it. I've been thinking about cloth, physics joints, mesh substraction (is it even possible?), some kind of animation... I don't have much time to do it. Can you show me the simplest way. Which tools and approach should i use? I'm not asking for full code or full solution only for some tips.
Tim Hunter mentioned a wonderful way, most perfect in 3D.
You can use another approach in 2D :
Inside OnCollisionEnter2D try finding hit points using Collision2D.contacts . See this reference .
Create some particle effect there.
Disable the enemy
Now play swallowing animation of the player.
At animation end, enable enemy again.
Maybe calculation is little tricky, still efficient.
I'm trying to build a scene with a number of prefabs placed onto a tiny planet, think something like this. The problem I am facing is that while I can place prefabs on a sphere easily using Control+Shift, they are not rotated and thus appear at terrible rotations. I'm aiming for them to be placed perpendicularly.
Currently I am aware of three solutions:
Place the objects in the scene using Control+Shift then manually rotate them into position.
Place the objects in the scene like before, then add a snippet of code to each of their Update methods: transform.rotation = Quaternion.FromToRotation(transform.up, transform.position - origin) * transform.rotation;
Like option 2, run the code and find some way to save the world state to the scene, but that is easier said than done. It seems like to much effort for something that should be trivial.
The first is tedious and hard to correctly align, the second is easy but renders your scene builder unrepresentative of your final game, and I have no idea where to start on the third. Is there a better way?
In the end I decided to perform all of the orientation manually using Control+Shift. As Johan suggested you could write your own [ExecuteInEditMode] Editor scripts, and if the planet I was foresting was significantly bigger I would have looked into it.
Be aware that if you do venture down the scripting path that the object isn't floating and fully clips through the surface. Manual placement may be necessary after all.
Maybe what I am going to ask you is unbelievable but It is my observation of Three days. I am unable to figure-out what is the problem. I have
asked my problem three times in different perspective but no luck.
Different but some kind (train) animation runs
at once on button click some animation complete on time while some not(play continuously-Don't know why). If I move my camera in the scene (a place where animation have to reach) then, my animation become complete but if I don't move or turn my camera then animation not complete even half hour passed.
I don't know what is the relation between camera and animation completion.
some things which I want to know
Why some animation complete on button click while the some not, even
the code is same and animation clips are right
Why those animation who play continuously, becomes complete as i walk
thorough my camera
What is relation b/w camera and animation play?
Is Train culling is the problem because i note that if i don't use the culling then, this problem occurring less(But occurring) as compare to train with culling.
Refer to my this question and answer. It were much disappointing that no one able to identify the problem (maybe lack of much attention to this question). After working 4/5 days finally I got this.
It were mainly animation Culling type Problem. For future use and help for the beginners like myself I am going to answer my own question here all questions are tightly associated with each other i.e., 1 answer to understand it:
Answer:
My animation culling type were selected to BasedOnRenderers which means that 'Animation is disabled when renderers are not visible'. i.e., my code were showing me that animation is playing but nothing acutal happening in my scene as my animation were far from camera view.
I solved this problem by selecting animation culling type to AlwaysAnimate (refer to this). It means that 'object is animated even when offscreen'.
Hope it will help others
I have an object which has a diffuse shader and on runtime I want the shader to switch to Diffuse Always Visible but this should trigger only if the unit is behind a specific object within the layer named obstacles.
First I tried to switch the object shader with the following code and the shader is changed in the inspector but not in the game during play. I tried placing and calling the shader from the resources and also created seprate materials but its not working.
Here is the code I am using in C#
Unit.renderer.material.shader = Shader.Find("Diffuse - Always visible");
As for the rest I was thinking of using a raycast but not sure how to handle this.
Thanks in advance
I only need the other concept now where the shader changes if a unit is behind an object!
For the trigger, how to handle it will depend a lot on how your camera moves.
To check in a 3D game, raycasts should work. Because whether or not something is "behind" something else depends on the camera's perspective, I would personally try something like this to start:
Use Camera.WorldToScreenPoint to figure out where your object is on the screen.
Use Camera.ScreenPointToRay to convert this into a ray you'll send through the physics engine.
Use Physics.Raycast and check what gets hit. If it doesn't hit the object in question, something is in front of it.
Depending on your goals, you might want to check different points. If you're just checking if something is more than halfway covered by an object, doing a single raycast at its center is probably sufficient. If you want to see if it's at all occluded, you could try something like finding four approximate corners of the object and raycasting against them.
If it's a 2D game or the camera is always at a fixed angle (for example, in a side scroller), the problem is potentially a lot simpler. Add colliders to the objects, and use OnTriggerEnter or OnTriggerEnter2D (along with the corresponding Exit functions). That only works if the tiniest bit of overlap should trigger the effect, and it only works if depth doesn't really matter (e.g. in a 2D game) so your colliders will actually intersect.