- Home /
How can I increase gameobject speed without increasing jump length ?
Hi, I am creating a 2D jump game with a player whose transform.position.x is increasing over time and a world randomly created. The player have the possibility to jump or do nothing to reach the next platform.
My jump is perform with a basic :
rigidbody2D.velocity.y = JumpForce;
If I scale the distance between platform with my Player speed, at high speed platforms are too far to eachother so they are not displayed on the screen.
Does someone have an idea on how Can I increase movment speed of my player, but keep the jump lenght same ?
Thanks
Answer by affreuxgeorges · Dec 13, 2013 at 01:06 PM
maybe try to increase a little the TimeScale. this way you don't mess up with physics and give the player a shorter time to react. it needs maybe some adjustements to look good, but I don't see why it should'nt work. anyway, platformer's physics has never been accurate especially in running games for that very reason. you want to increase speed to reduce time between obstacles, so timescale should work with some refining on animations and particles speed especially.
God, I can deal all my game with an increase of TimeScale. No more lenght jump issue and no need to speed up my player.
Is it just a dream or is there bad side of doing it this way ? By the way thanks :)
the bad side, probably, is if you want to have "normal speed objects" like animations or particle effects or camera movement, so you'll need to add some sort of management to increase global timescale and handle objects you want to behave normally.
the other solution would be to use custom physics. => set your player rigidbody to is$$anonymous$$inematic, then in a script you have an update like :
{ rigidbody.velocity = Vector3.zero; apply$$anonymous$$ovement(); applyGravity(); } if you reset your velocities you simulate maximum friction, so jump should be applied each frame during the jump, by a certain amount which can be defined by a animationcurve for exemple.
custom phisics is often used on platformers, cos in platformers, what really matters is character metrics (jump hight, length, speed) in conjunction to level design. We don't care about realistic simulations here. we want gameplay.
cheers.
Answer by Matthew Scott · Dec 13, 2013 at 07:42 AM
This doesn't really make too much sense, I would have thought it would be a bad idea to change the jump length the faster you go, as players are always trying to gauge jump distances, it would be extremely confusing to have your player jump smaller distances as you increase your speed...if your platforms are procedurally / randomly generated my suggestions would be to place your PLATFORMS further apart using an algorithm that's based on either player movement speed OR distance from start to decide how far apart to place each platform...rather than mess around with the natural physics.
Seems you already had that in place and it was working, I'd keep it that way. Two things you can do here though to try and keep your upcoming platform in the screen.
Zoom your camera OUT the faster you get so you see MORE of whats coming.
Cap the movement speed to a point where you can just see the next upcoming platform.
Thanks for the answer. Yes I did some test to place my platform regarding to the player speed but by doing this the game is quite easy. The time between each platform stay the same and the player have same time to react at low speed than at hight speed.
I thought it was a common issue as there is many jump game on mobile, like Temple Run ...
I will try to work on rigibody Gravity and Drag to sort it out. Any help is welcome :)
Answer by KellyThomas · Dec 13, 2013 at 02:33 PM
Physics tells us that the time an upward moving projectile will take to complete it's arc and return it's original height can be found with:
time == (2 * velocity.y) / gravity
Meanwhile the horizontal distance traveled over time can be found with:
distance == velocity.x * time
// solve for time
time == distance / velocity.x
When we combine the two formula we have:
(2 * velocity.y) / gravity == distance / velocity.x
Now you say that velocity.x
increases as play continues, and you want distance
to remain constant, this leaves velocity.y
and gravity
as the values you could modify:
velocity.y / gravity == distance / (velocity.x * 2)
// solve for velocity.y
velocity.y == (distance * gravity) / (velocity.x * 2)
// solve for gravity
gravity == (2 * velocity.y * velocity.x) / distance
So by modifying velocity.y
or gravity
or both to match these formula you will result in a jump of the same horizontal distance, however as velocity.x
increases the height of the arc will decrease.
This if followed strictly is unlikely to result in interesting gameplay. I would suggest defining the maximum and minimum jump distance your game will support and allowing some variation within that range.