- Home /
Ball rolling through object
I am trying to make a simple pinball game. For the trigger that launches the ball I want to have that activated by the space bar. When I hit space with the script below sometimes the ball goes all the way up like I want, other times it goes halfway and other times it glitches through my Blender model and falls into space. I don't know if it is the code or if it is in Unity itself. I have tried the "Don't Go Through Things" script already and that did not help.
using UnityEngine;
using System.Collections;
public class Movement : MonoBehaviour
{
public float speed = 5f;
public float upspeed = 5f;
void FixedUpdate ()
{
if(Input.GetKeyUp(KeyCode.Space))
transform.position += new Vector3(speed * Time.deltaTime, upspeed * Time.deltaTime, 0.0f);
rigidbody.AddForce (transform.position);
}
}
Answer by alok-kr-029 · Apr 02, 2015 at 12:46 PM
try using this code for your jump as I was having the same problem I solved it by using this
transform.Positon = transform.position + new vector3(0,jumpheight,0); or
Transform.Translate(new vector3(0,jumpheight,0) ,Space.World)
hope this will work
Your answer
![](https://koobas.hobune.stream/wayback/20220613191926im_/https://answers.unity.com/themes/thub/images/avi.jpg)