Quantcast
Channel: Questions in topic: "addforce"
Viewing all articles
Browse latest Browse all 1264

DontGoThroughThings, Rubberbanding

$
0
0
I'm using the C# script from the wiki http://wiki.unity3d.com/index.php?title=DontGoThroughThings Everything seemed to be working untill I tried to move the ball. I use a script that counts the time you've held down your mouse button for and then multiplies that with the force. using UnityEngine; using System.Collections; public class Shoot : MonoBehaviour { public static int ShootTimes = 1; public Rigidbody projectile; float shotForce = 5000f; public float moveSpeed = 10f; public float charge; public Transform shotPos; public bool charging=false; public float lockedRotation = 0; float chargeTimeBegin = 0.0f; float Charge(float number, float chargedTime){ return number * chargedTime; } void Start () { } void Update () { if (Input.GetButtonDown("Fire1")) { chargeTimeBegin = Time.timeSinceLevelLoad; } else if (Input.GetButtonUp("Fire1")) { float chargedTime = Time.timeSinceLevelLoad - chargeTimeBegin; Debug.Log(chargedTime); if (chargedTime > 2.99) { chargedTime = 3; } if (ObjectRotator.MouseDown == false) { Rigidbody shot = Instantiate(projectile, shotPos.position, shotPos.rotation) as Rigidbody; Destroy(GameObject.FindWithTag("Player")); shot.AddForce(shotPos.forward * Charge(shotForce, chargedTime)); ShootTimes = ShootTimes + 1; } } } } After I release the mouse button It goes backwards for like 1 sec then starts going forward and stops. The thing is I can't figure out why it goes backwards. NOTE: This is on a flat ground and not against a wall.

Viewing all articles
Browse latest Browse all 1264

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>