- Home /
How to implement Earthbending?
Hi!
I'm making an Avatar sort of game with bending mechanics and I have been struggling for a while now with implementing a good-looking rock throw attack. There is very little documentation about spawning things so they come out of the ground then forward so if you could shed som light on the matter please do.
The rock in question.
Here is my current script:
groundextentbounds = groundcollider.bounds.extents;
groundmaxbounds = groundcenterbounds + groundextentbounds;
groundcenterbounds = groundcollider.bounds.center;
rockextentbounds = earthcollider.bounds.extents;
rockcenterbounds = earthcollider.bounds.center;
rockmaxbounds = rockcenterbounds - rockextentbounds;
}
// Update is called once per frame
void Update()
{
SpawnLocation = player.transform.position - rockextentbounds + player.transform.forward * 5;
if (Input.GetKeyDown(KeyCode.E))
{
Instantiate(Earthrb, SpawnLocation, player.transform.rotation);
}
You didn't really explain your problem. Documentation for Instantiate is good, it says everything there is about this method. Any displacement and movement you have to do yourself.
As a side note to see your link one needs to have an account on that side. Upload picture to a site where you don't need an account (like imgur) or directly here
$$anonymous$$y problem is with the displacement when im instantiating. What I want to do is so the rock comes up from the ground and then flies forward like in the series.
You would have to watch some tutorials for that. It's a simple but quite complex topic and explaining it here would take too long. This would be a good place to start I think
Answer by TheXWolf · May 06, 2019 at 01:33 PM
This is a very complicated question. First you need to instantiate an object and then most likely watching the transform or the rigidbody move it to a position. (Depending how realistic vs accurate you want.) Or another way to do it, would be to have it be part of an animation.
Spawning in an object that has an animation on it that moves it in and fires itself forward. If you're doing this with physics logic it would be quite complex. Most likely you'll need 2 scripts, the one instantiating it shouldn't really know it exists, simply create it and let it go. A second script on the object itself handling its position either via physics or straight transform movement.
I would suggest looking up Transform.Translate as well as Rigidbody.Velocity. Additionally you'll need to track when it's raised high enough. Again, the simplest way would be spawn in the object animating it's relative position, and affecting the rigidbody velocity at the point where it starts moving forward rather than up so it continues.