- Home /
How would I go about making objects around player float up into the air?
I'm trying to make it so while the player is charging / holding down shift or so, all rigidbodies around him will ~float up into the air~, as if gravity slowly pulled them up, then they stop at a max height I set.
How would I go about doing such a thing? I've looked into a lot of levitate / floating questions, but none of them seem to help me with this specifically.
Answer by MSpiteri · May 08, 2014 at 10:52 AM
You can use OverlapSphere. Refer to this: https://docs.unity3d.com/Documentation/ScriptReference/Physics.OverlapSphere.html
With that, you will be able get all the colliders around the player within a certain radius. Then, for each, check that they have a rigidbody and make them levitate (remove their gravity and increase their y-position slowly, etc).
If you need another example on how to use the OverlapSphere, go here:
https://docs.unity3d.com/Documentation/ScriptReference/Rigidbody.AddExplosionForce.html
Oh! I'm trying to mess around with this. I was wondering, if this could be used for skills? I mean, taking the game League of Legends, when you click a spell, the area where it will hit, will be marked by a white raycast (atleast so it seems). If I would want to show the radius from the AddExplosionForce as LoL does, do you have any idea how to do such a thing?
Hello again. Before I go to your question, please note that I gave you this link to the AddExplosionForce example so that you can see how you can use the "OverlapSphere" command and the "foreach" loop. In you case you would NOT apply the explosion force; ins$$anonymous$$d, you would simply increase the y-position of each rigidbody to make them float.
Now, going back to your new question about how to show the radius, if you intend to draw a sphere at the point of impact, then you can simply instantiate a semi-transparent sphere at the point of impact and set its radius (scale) equal to the radius of the explosion.
I ofcourse did that, the problem I run into is that because the rigid bodies have gravity, they will jump up then fall down and continue like that till the force is back down.
What I'm trying to achieve is like the $$anonymous$$an Of Steel flight scene, when he is about to jump you see dirt and small rocks lift up. That's what I want to achieve, just with objects around you.
Do you have any tips on how to fix this?
So far my script is if you hold shift down, a variable will charge up to thr max value of 5, while its charging the force of pulling objects up id increased aswell. When you let go of shift, everything falls back. I am on phone atm, but if script is needed I can log onto pc. Thanks btw, this one is hurting my head
You can disable a rigidbody's gravity, so you could do that OverlapSphere thingie and then just disable gravity for all colliders inside that OverlapSphere, then set a variable for gradual velocity on the Y axis and once that float variable is at a maximum speed that you want, then just slow down and make it look like it's floating in the air.
I'll write you an example if you want.
Answer by PvTGreg · May 08, 2014 at 10:50 AM
just off the top of my head but you could add a box collider to the player and set it as trigger and add a script that would look for a tag that is on the objects around the player and when it collides with them it could turn gravity off on the objects(on a rigidbody) and add force upwards causing them to float up
Ah, I think that would work, but the objets wouldnt look realistic (gravity rotating them or such). Any way to enchance the "realistism" a bit?
Your answer
Follow this Question
Related Questions
I want a flying / floating Charcter 1 Answer
My enemy keeps floating in mid air and need help raycasting! 0 Answers
Simulating Water not working.. 1 Answer
3rd person 1 Answer
Exclude Objects From FloatingOrigin 1 Answer