Question by
LearningGaming · Aug 28, 2018 at 04:35 AM ·
c#movementcharactercontrollerbeginnerjumping
How do i move a cube like an actual cube?,How Can i Move a Cube?
Like mentioned in the question, how do i do just that?
void FixedUpdate () {
if (Input.GetKey("w"))
{
rb.AddForce(0, 0, w*Time.deltaTime,ForceMode.VelocityChange);
}
if (Input.GetKey("s"))
{
rb.AddForce(0, 0, -w * Time.deltaTime, ForceMode.VelocityChange);
}
if (Input.GetKey("a"))
{
rb.AddForce(-a * Time.deltaTime, 0, 0, ForceMode.VelocityChange);
}
if (Input.GetKey("d"))
{
rb.AddForce(a * Time.deltaTime, 0, 0, ForceMode.VelocityChange);
}
if (Input.GetKey("space"))
{
rb.AddForce(0, jump * Time.deltaTime, 0, ForceMode.VelocityChange);
}
}
When i run this, there is the issue when i simultaneously press W and A, the cube would slide diaganoly. Plus, The cube wouldn't move like a normal cube would, there are times when it bounces. Finally, how do i made the cube jump properly? Thanks,How can i move a cube, like an actual Cube?
void FixedUpdate () {
if (Input.GetKey("w"))
{
rb.AddForce(0, 0, w*Time.deltaTime, ForceMode.VelocityChange);
}
if (Input.GetKey("s"))
{
rb.AddForce(0, 0, -w * Time.deltaTime, ForceMode.VelocityChange);
}
if (Input.GetKey("a"))
{
rb.AddForce(-a * Time.deltaTime, 0, 0, ForceMode.VelocityChange);
}
if (Input.GetKey("d"))
{
rb.AddForce(a * Time.deltaTime, 0, 0, ForceMode.VelocityChange);
}
if (Input.GetKey("space"))
{
rb.AddForce(0, jump * Time.deltaTime, 0, ForceMode.VelocityChange);
}
}
What's wrong with this code? When I try and run it, if i press W and A at the same time, the cube would be like sliding diagonally. Plus, there is the problem with the cube not rolling like a normal cube would do. Finally, how do i make the cube jump properly? Thanks
Comment