Something more sensible to go here

float DistanceMoved = FVector::Dist(StartLocation, CurrentLocation);

//Reverse direction of motion if gone too far

if (CurrentLocation.X > -1300 && PlatformVelocity.X < 0) {

PlatformVelocity = -PlatformVelocity;  



So basically I tried to challenge my self to do it before but it didnt work so I’m doing it the videos way but would love if someone explained why it wouldnt work.

The issue you have there is that you have hard-coded the X position of the platform and also assumed it is negative, and that it will only travel in one axis.

This means the platform you have implemented will only work in a single direction at a single place. The course implementation is direction independent as it relies on the distance between 2 points - so it could even be up-down.

I hope this helps.

I’m sorry but could you explain it a little more i’m still confused mb.

if (CurrentLocation.X > -1300 && PlatformVelocity.X < 0) {

This expects the location to always be between -1300 and 0 and only change the direction if the X value lands between those values.

if the location is CurrentLocation.X -1600, 2000 or something else it will not change directions.

The original code is designed to work out the distance between start and end location, and then this distance will checked against the current from the current target location, and if it is within a tolerance, reverse the direction.

Does this make sense?

Alright just a min I removed the and PlatformVelocity.X<0. Anyway So basically what your saying is that my currentlocation isn’t always being updated so it will never change directions? because It is moving above -1300 and nothing is happening with the platform.

Yes, also the checks will only permit it reverse if moving in the X value, assuming it is within the given bounds.

1 Like

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.

Privacy & Terms