Hi, I am looking at making a game where the players can walk on walls whilst still being able do stuff such as jump and shoot. could anybody help me with the script for this as im still a begginner in unity. Thanks
i have looked at this thread and applied it to my game but my player just seems to glitch and fall through the walls in my game, any fix for this?
Maybe this helps: Code (csharp): /* Create a sphere object and scale every axis up a bit (say by 10-15m) Create a cube and attach this script to it Script requires a sphere collider as an argument so select the sphere game object. Use arrow keys to fly around! */ var rotationSpeed = 120.0; var translationSpeed = 10.0; var height = 2.0; //height from ground level private var centre : Transform; //transform for planet private var radius : float; //calculated radius from collider var planet : SphereCollider ; //collider for planet function Start () { //consider scale applied to planet transform (assuming uniform, just pick one) radius = planet.radius * planet.transform.localScale.y; centre = planet.transform; //starting position at north pole transform.position = centre.position + Vector3(0,radius+height,0); } function Update () { //translate based on input var inputMag = Input.GetAxis("Vertical")*translationSpeed*Time.deltaTime; transform.position += transform.forward * inputMag; //snap position to radius + height (could also use raycasts) targetPosition = transform.position - centre.position; var ratio = (radius + height) / targetPosition.magnitude; targetPosition.Scale(Vector3(ratio, ratio, ratio) ); transform.position = targetPosition + centre.position; //calculate planet surface normal surfaceNormal = transform.position - centre.position; surfaceNormal.Normalize(); //GameObject's heading var headingDeltaAngle = Input.GetAxis("Horizontal") * Time.deltaTime * rotationSpeed; headingDelta = Quaternion.AngleAxis(headingDeltaAngle, transform.up); //align with surface normal transform.rotation = Quaternion.FromToRotation( transform.up, surfaceNormal) * transform.rotation; //apply heading rotation transform.rotation = headingDelta * transform.rotation; } Please show me your result, Thanks
it works and it on the same lines of what i want. i want to create a first person shooter game such as counter strike etc with the player having the ability to go anywhere on the map by sticking to walls/ceilings and treating them as floors.
I was working with that script too (still am) There was a bit of an error i was getting, and the fix had been moving the collider up in the inspector (so it was underneath the transform on the empty object) not sure why... this fixed it... and not sure it'll fix your problem but it really helped with mine.