Not counting score when jump landing is on same platform

I have an endless jumper where a new platform gets instantiated after reaching the next platform by entering it's box collider as trigger. Also when you enter the platform's box collider the score gets inscreased by one.
But here is the problem, if the force on the jump is to low you still land on the same platform so the score gets increased although you are still on the same platform. How can I prevent this from happening without changing the settings on the jumpforce? I was thinking on checking if I'm still on the same platform, but since I'm new to Unity I don't know really where to start.
Can someone help me in the right direction?
Answer by Jojoba007 · Feb 16, 2017 at 08:19 AM
Got it working, it became another approach, but its working.
// Increment score and instantiate platform. Also check if last platform was allready landed on
if (ScoreManager.instance != null && GameManager.instance != null) {
if (target != lastPlatformJumpedOn) {
lastPlatformJumpedOn = target;
ScoreManager.instance.IncrementScore ();
ScoreManager.instance.HighScore ();
GameManager.instance.CreateNewPlatformAndLerp (target.transform.position.x);
}
} else {
ScoreManager.instance.IncrementScore ();
GameManager.instance.CreateNewPlatformAndLerp (target.transform.position.x);
lastPlatformJumpedOn = target;
}
}
}
Answer by AmoVires · Feb 15, 2017 at 11:45 AM
You can store character position pre and post jump. If distance travelled is >x then add score?
@AmoVires That sounds like a good approach, thanks. Could you maybe give me a little bit more info on how to handle this in code?
@Jojoba007 Easiest way is 2 variables I guess. Upon jumping you save his position (x?) into a variable and upon landing you save his new position into another variable.Then compare them. OnCollision/OnTrigger Enter/Exit should do the trick.
P.S Sorry about late reply, fell asleep.
void OnTriggerExit2D (Collider2D other)
{
x = Player.transform.position.x;
}
void OnTriggerEnter2D (Collider2D other)
{
y = Player.transform.position.x;
if (y - x > distance) {
score++;
}
That should do the trick.You have to do a bit of tweaking and make distance as big as the platform width
Your answer
Follow this Question
Related Questions
instantiated prefab doesn't follow spawn rotation 1 Answer
Call function for instantated prefab. "Object reference not set" 1 Answer
Simple Prefab Instantiate "(Clone)" Question 3 Answers
How to Change the Variables of an Instantiated Object? 0 Answers
Check if a large number of gameobjects are colliding 1 Answer