18-12-2020, 01:39 PM
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;
}
}
}