Pinball Machine. HingeJoint Flippers don't work. Ball spawns in wrong direction
Hi, I'm a Student from the Netherlands and our teachers have a hard time with giving us enough hours in class to get enough info to make the pinball machine before we get to our deadline (next monday). so we have to do alot of research of our own.
I have 2 problems none of my classmates weren't able to help with:
My flippers keep spassing out, move figerously or inproper, I tried alot of things but can't fix it. Theyre put down with HingeJoints and this is the scipt I use to move it:
using UnityEngine; using System.Collections;
public class Flipperspin : MonoBehaviour {
public float flipperstrength; public float pushforce; private HingeJoint hinge; void Start () { hinge = GetComponent<HingeJoint>(); } // Update is called once per frame void FixedUpdate () { if (Input.GetButtonDown("Jump")) { Vector3 f = transform.up * flipperstrength; Vector3 p = (transform.right) + transform.position * pushforce; GetComponent<Rigidbody>().AddForceAtPosition(f, p); } } }
The second problem I found is that when I respawn my ball with fire1, the ball gets shot upwards. But I need it to go down, but I have no idea how to turn it around. I placed the script on an Empty object, and placed the empty object where I want it to spawn. Again the script I use for this:
using UnityEngine;
using System.Collections;
public class PinballSpawn : MonoBehaviour { public float power; public GameObject prefab; public GameObject pinballSpawn;
void Update()
{
if(Input.GetButtonDown("Fire1"))
{
SpawnPinball();
}
}
public void SpawnPinball()
{
GameObject pinball = (GameObject)Instantiate(prefab, pinballSpawn.GetComponent<Transform>().position, pinballSpawn.GetComponent<Transform>().rotation);
pinball.GetComponent<Rigidbody>().velocity = transform.forward * power;
}
}
Hopefully someone will be able to help, any input is apreciated!
Your answer
Follow this Question
Related Questions
Reset Position 1 Answer
How to move a 2D object toward the position it is pointing to? 0 Answers
Bullet won't fly forward 0 Answers
Character moves without arrow keys 0 Answers
is it possible for velocity vectors to be added on the players axis? 1 Answer