Quist
June 15, 2015, 1:55pm
1
So i have a ball rolling game with a sphere as player 1.
Right now the movement works great when its jumping from 1 surface to another and so but the problem is when it goes down a hill.
When the object goes down a straight hill it will fly off like and airplane if i hold the “W” forward button down.
If i add more mass it wont do so, but then the player 1 moves too slow to jump from 1 surface to another.
What do i do :?
Currently the player object have the mass “2” and the following movement script.
#pragma strict
var jumpHeight = 0.02;
static var jumpCount = 0;
var canJump = true;
function FixedUpdate ()
{
if (Input.GetKey (KeyCode.W) && jumpCount == 0)
{
GetComponent.<Rigidbody>().AddForce (Vector3.forward * 30);
}
if (Input.GetKey (KeyCode.S))
{
GetComponent.<Rigidbody>().AddForce (Vector3.back * 20);
}
if (Input.GetKey (KeyCode.A))
{
GetComponent.<Rigidbody>().AddForce (Vector3.left * 28);
}
if (Input.GetKey (KeyCode.D))
{
GetComponent.<Rigidbody>().AddForce (Vector3.right * 28);
}
if (Input.GetKey (KeyCode.Space) && jumpCount == 0)
{
GetComponent.<Rigidbody>().AddForce(Vector3.up * jumpHeight, ForceMode.Impulse); jumpCount = 1;
}
{
GetComponent.<Rigidbody>().velocity = Vector3.ClampMagnitude(GetComponent.<Rigidbody>().velocity, maxVel);
}
}
var maxVel : float = 10.0;
function OnCollisionEnter (hit : Collision)
{
if(hit.gameObject.tag == "Floor")
{
jumpCount = 0;
}
}
Simo
June 15, 2015, 2:10pm
2
TotalForce = massgravity + Vector3.forward 30
//mass = 2
TotalForce = -Vector3.up2f 9.81f + Vector3.forward2f 15f
your forward factor is 15 > 9.81
if your mass = 3 your factor will be 10 == gravity in that cas I think it should be ok
hope that make sense
A lot of games fake it by having two sets of physics. One takes place in midair and applies gravity. The other takes the ball and attaches it to the surface of the world as it moves and then controls its acceleration, velocity, and downhill extra acceleration by variable instead of physics.
This will give you more control over the ball without sacrificing movement speed or the appearance of gravity.
Quist
June 17, 2015, 9:04pm
4
GargerathSunman:
A lot of games fake it by having two sets of physics. One takes place in midair and applies gravity. The other takes the ball and attaches it to the surface of the world as it moves and then controls its acceleration, velocity, and downhill extra acceleration by variable instead of physics.
This will give you more control over the ball without sacrificing movement speed or the appearance of gravity.
Could you maybe give me an example of a script which would lgue the player to the ground when it aint in the air?
Not word for word, as I’m not on my development computer currently. The gist of it is, though, that you’d fire a raycast downwards with a layer mask that only hits the terrain. It would then place the ball a specific distance above the ground.
When you jumped, it would set a boolean to true that would let physics take over. On hitting the ground, it’s set back to false and your raycast would resume.
Quist
June 17, 2015, 10:19pm
6
GargerathSunman:
Not word for word, as I’m not on my development computer currently. The gist of it is, though, that you’d fire a raycast downwards with a layer mask that only hits the terrain. It would then place the ball a specific distance above the ground.
When you jumped, it would set a boolean to true that would let physics take over. On hitting the ground, it’s set back to false and your raycast would resume.
Alright thanks a lot - ill try and mix some stuff together ^^