- Home /
Question by
jwalnahdi · May 11, 2021 at 05:41 PM ·
roll a ball
Hi this code is to control roll a ball i have inquiry about jump part, how can i return the ball to the Surface after jumping this is the code
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class movment : MonoBehaviour { public Rigidbody rb; public float forceAmount; public float sideForceAmount; bool _right; bool _left; bool _jump; // Start is called before the first frame update void Start() {
}
// Update is called once per frame
void Update()
{
if (Input.GetKey(KeyCode.A))
{
_left = true;
}
else
{
_left = false;
}
if (Input.GetKey(KeyCode.D))
{
_right = true;
}
else
{
_right = false;
}
if (Input.GetKey(KeyCode.S))
{
_jump = true;
}
else
{
_jump = false;
}
}
void FixedUpdate()
{
rb.AddForce(0, 0, 0.3f ,ForceMode.VelocityChange);
if(_right)
{
rb.AddForce(0.2f, 0, 0 ,ForceMode.VelocityChange);
}
if(_left)
{
rb.AddForce(-0.2f, 0, 0 ,ForceMode.VelocityChange);
}
if(_jump)
{
rb.AddForce(0, 0.2f, 0 ,ForceMode.VelocityChange);
}
}
}
Comment
Your answer
Follow this Question
Related Questions
Roll a Ball - Video 7 error 1 Answer
Activating Objects with collision of another objects 1 Answer
How to make an fps game while the character rolls like a ball 2 Answers
How to change addForce direction depending on camera direction 1 Answer
How do I find out a compile error that wont show up. 1 Answer