So I’m working on a Mario-Galaxy-esque platformer with a lot of physics mechanics, however this is my first real dive into the physics of unity and I think I’m making some conflicts for myself.
The current problem I’m trying to overcome occurs when I add velocity to my player’s rigidbody through a conveyer belt platform, that functions by adding velocity to the player in a direction that I choose.
While the player is colliding with the conveyer belt, they will be pushed in that direction at x velocity, just like I programmed. The issue is that while this is happening my jump function is either stunted or negated, practically never leaving the ground.
This only happens when colliding with the conveyer belt, and I believe the problem lies in conflicting velocity changes in the FixedUpdate functions in each script.
I can’t += velocity with the conveyer belt, because it will accelerate for as long as I’m touching the belt. I tried changing from CollisionStay to CollisionEnter and Exit but it didn’t help.
Is there some kind of way I can specify a constant velocity in a direction without overriding my jump’s velocity change?
Player Motor Script.js (Excerpt)
function FixedUpdate(){
if (DownwardG){
rigidbody.AddForce(-gravity*rigidbody.mass*Vector3.up);
}
if (!ZeroGrav){
if (!DownwardG){
// apply constant weight force according to character normal:
rigidbody.AddForce(-gravity*rigidbody.mass*myNormal);
}
}
if (Input.GetButtonDown("Jump")){ // jump pressed:
if (isGrounded){ // no: if grounded, jump up
//rigidbody.velocity += jumpSpeed * myNormal;
rigidbody.velocity = jumpSpeed * myNormal;
// rigidbody.velocity = Vector3(0,0,0);
print("Jump!");
//rigidbody.AddForce((550+gravity*rigidbody.mass)*myNormal);
}
}
Conveyer Belt Script.js (In its entirety)
var x : float;
var y : float;
var z: float;
//private var JumpFix : boolean = false;
//private var OriginalVelocity : Vector3;
private var MoveIt : boolean = false;
private var ObjectToMove: GameObject;
function FixedUpdate(){
if (MoveIt){
ObjectToMove.rigidbody.velocity = Vector3(x,y,z);
//I thought something like this might help but it didn't, at least in the way I attempted
//collidingObject.rigidbody.velocity = OriginalVelocity + Vector3(x,y,z);
}
}
function OnCollisionStay(collidingObject : Collision)
{
print(x);
print(y);
print(z);
ObjectToMove = collidingObject.gameObject;
MoveIt = true;
}
function OnCollisionExit(collidingObject : Collision){
print("exited");
MoveIt = false;
ObjectToMove.rigidbody.velocity = Vector3(0,0,0);
}