#Looks like he s just spawning a bunch of
1 messages · Page 1 of 1 (latest)
Thanks for the help, if i would like to achieve similar effects where an object spawn and launch upwards (maybe random directions) when certain condition is met. is it right to use the addforce() function to do so
Yeah should work just fine.
The advantage to setting velocity directly is that if you want super tight controls (like say in Celeste) and you wanna spend a lot of time tweaking it it allows for a lot of fine control.
Personally I usually just use .AddForce for most things, it's much easier. But leads to more... realistic, physics based feel. Less snappy.
Edit: Fixed typos.
Thanks! i am trying to implemente the the effect i mention above. Currently the condition and spawning of the coin is working, but the force is not applied to the coin after it spawn, i assume is the part where i handle the rigid body is wrong. do you have any idea or suggestions?
{
// Start is called before the first frame update
Rigidbody rd;
public static launchUp instance;
public GameObject coinPrefab;
void Awake()
{
if (instance != null)
Destroy(gameObject);
else
instance = this;
}
void Start()
{
rd = coinPrefab.GetComponent<Rigidbody>();
}
public void launch(){
GameObject coin = Instantiate(coinPrefab);
coin.transform.position = new Vector3(0.28f,5.7f,13.5f);
rd.AddForce(Random.Range(-3,3),10,Random.Range(-3,3), ForceMode.Impulse);
}
// Update is called once per frame
void Update()
{
}
}
this is the coinPrefab's rigid body settings, i have tried to toggle is Kinematic but the coin will fall off the platform i create, so i dont think it should be toggle off.
Yea setting something to kinematic makes it ignore physics forces
so i should toggle off is Kinematics? but if i do so the coin would not stay on the platform i create.
So...
Your launch function instantiates an object (using a prefab) and assigns it as GameObject "coin".
Then you set this new coins transform.position. That seems right to me.
But then you add force to "rd". "rd" is a Rigidbody you define up top.
You aren't applying it to the rigidbody of the thing you are spawning.
You could try coin.GetComponent to get the new coin's Rigidbody, and then apply force to it.
so i should set rd to be coin.GetComponent<Rigidbody>();
Yeah
hmm then ill need to find someway to make it stay on the platform
I mean. If I remember right kinematic affects collisions. Like physX stuff. It might also make it ignroe gravity but I don't remember it off the top of my head.