Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
FirstPersonLauncher with Softbody itself
#1
Hey i would like to shoot some softbodies.
so i want to do a mix between the actor spawner and the fps launcher.
the softbody does not have a rigidbody so how do apply initial velocity to the particles?
i did pose the whales with obi
and now i need to shoot crabs.
https://vimeo.com/492231983
Reply
#2
(18-12-2020, 11:59 AM)nbac85 Wrote: Hey i would like to shoot some softbodies.
so i want to do a mix between the actor spawner and the fps launcher.
the softbody does not have a rigidbody so how do apply initial velocity to the particles?
i did pose the whales with obi
and now i need to shoot crabs.
https://vimeo.com/492231983

Same way as you'd do with a rigidbody:

Quote:softbody.AddForce(velocity,ForceMode.VelocityChange);

See:
https://docs.unity3d.com/ScriptReference...Force.html
https://docs.unity3d.com/ScriptReference...hange.html

Only difference between rigidbodies and softbodies is that rigidbodies have a single linear velocity (measured at its center of mass), while softbodies have multiple velocities (one per particle). But you can use AddForce() the same way with both.
Reply
#3
yes thanks ! i have to add very high values else its working perfectly!

Code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Obi;

public class ActorSpawner : MonoBehaviour {

    public ObiActor template;

    public int basePhase = 2;
    public int maxInstances = 32;
    public float spawnDelay = 0.3f;
   
    private int phase = 0;
    private int instances = 0;
    private float timeFromLastSpawn = 0;

    public float power = 2;


    // Update is called once per frame
    void Update () {

        timeFromLastSpawn += Time.deltaTime;

        if (Input.GetKeyDown(KeyCode.Space) && instances < maxInstances && timeFromLastSpawn > spawnDelay)
        {
            Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);

            GameObject go = Instantiate(template.gameObject,ray.origin, Quaternion.identity);
            go.transform.SetParent(transform.parent);

            ObiSoftbody sb = go.GetComponent<ObiSoftbody>();
            sb.AddForce(ray.direction * power * 10000, ForceMode.Force);

            go.GetComponent<ObiActor>().SetPhase(basePhase + phase);

            phase++;
            instances++;
            timeFromLastSpawn = 0;
        }
    }
}
Reply
#4
Remember that the change in velocity or acceleration = force/mass, so if the softbody mass is high, you will have to use a large force for it to result in enough acceleration. Using ForceMode.VelocityChange as indicated above might be a better idea if you don't want mass to affect launch speed.
Reply