Add Velocity through a 'conveyer belt', and Jumping While Doing So (Can't jump on it)

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);
	}

Yeah, your players Jump velocity is only having effect for one frame when the player is on a Conveyor belt., because you’re hard setting the velocity instead of adding to it.
You should handle your Jumping with an AddForce call so that you preserve any directional velocity your player has starting a jump.
And with your conveyor belt, try something like:

var x : float;
var y : float;
var z: float;
var max_speed: float;

//private var JumpFix : boolean = false;

//private var OriginalVelocity : Vector3;

private var MoveIt : boolean = false;

private var ObjectToMove: GameObject;

 

 

function FixedUpdate(){

 

if (MoveIt){

if(ObjectToMove.rigidbody.velocity.magnitude < max_speed)
{
ObjectToMove.rigidbody.velocity.AddForce(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);

    }
ObjectToMove.rigidbody.velocity.AddForce(Vector3(x,y,z));

This line is giving me a MissingMethodException.

It appears to be spelled and capitalized correctly, I’m not sure why it’s returning with this. Any ideas?

EDIT: The problem was you left .velocity in there, it should instead be simply rigidbody.AddForce. This works great now, though! Thanks a lot :smile: