- Home /
Other
Keep object on rail?
I am creating a snowboarding game, I would like the snowboarder to be able to jump onto a rail and stick on it if hes holding c. I can't think of any possible way to do this with my knowledge and I can't find anything similar online with any sample code. If my character touches the rail, It should be center locked on it until the end of it or until he jumps off.
For reference, Im aiming for this ( go to 5:54 ) : https://www.youtube.com/watch?v=cjXlBHEzTXQ
Any help will be appreciated, Will give points to anyone who can help me with a starter code too ( JAVA SCRIPT )
Thanks
Answer by highpockets · Apr 16, 2019 at 02:44 PM
I would suggest that you get whatever the direction of the rail is running parallel to in world space and when the snowboard’s bottom collides with the rail and the player is pressing the C button, then keep your player constrained to only move in that direction.
I think you should try to do something with that info and come back showing some coding attempt if it doesn’t workout and then we can help out.
Hi, Thanks for the response.
I am wanting to have curved rails ins$$anonymous$$d of one direction. I have no clue how to make it follow a curve.
if(OnRail == true){
GetComponent(TrailRenderer).enabled = true;
snowTrail.active = true;
var hitRail : RaycastHit;
if (Physics.Raycast(transform.position, Vector3.down, hit)) {
var distanceToRail = hitRail.distance;
transform.rotation = Quaternion.FromToRotation(transform.up, hitRail.normal) * transform.rotation;
Snow$$anonymous$$esh.transform.rotation = Quaternion.FromToRotation(transform.up, hitRail.normal) * transform.rotation;
distToGround = distanceToRail;
}
}
That’s definitely a little more difficult. But is it possible to setup waypoints within the curve. Then get the direction from the closest waypoint to the next waypoint in line and once you reach the next waypoint you get the direction from that waypoint to the next, etc.. Either that or you could setup some pivot points to rotate around, the pivot point would obviously have to be the same distance away from any point in the curve.
Follow this Question
Related Questions
Curved transform.translate 1 Answer
Pause online game 1 Answer
Spline Controller (javascript) error 2 Answers
how to continue spline? 0 Answers