Log in or register to post comments

Ray Casting Help

August 16, 2018 - 10:20am #1

Hello

I'm trying to create an educational AR app for android. I was checking some tutorials on ray casting and i found one for audio but i need one to activate some animations. I have zero developer experience. I just basically started on my dev journey. Does anyone know how to re-purpose this code to activate animations?

 

Below is the current script i have.

using System.Collections;

using System.Collections.Generic;

using UnityEngine;

public class SoundconVan : MonoBehaviour

{

public AudioClip[] aClips;

public AudioSource myAudioSource;

string btnName;

// Use this for initialization

void Start()

{

myAudioSource = GetComponent<AudioSource>();

}

// Update is called once per frame

void Update()

{

if (Input.touchCount > 0 && Input.touches[0].phase == TouchPhase.Began)

{

Ray ray = Camera.main.ScreenPointToRay(Input.GetTouch(0).position);

RaycastHit Hit;

if (Physics.Raycast(ray, out Hit))

{

btnName = Hit.transform.name;

switch (btnName)

{

case "PlayButton_Van":

myAudioSource.clip = aClips[0];

myAudioSource.Play();

break;



case "PauseButton_Van":

myAudioSource.clip = aClips[0];

myAudioSource.Pause();

break;



case "StopButton_Van":

myAudioSource.clip = aClips[0];

myAudioSource.Stop();

break;

default:

break;

}

}

}

}

}

 

 

Thank you in advance.

Ray Casting Help

August 20, 2018 - 2:01am #2

Just in case anyone else is looking for something similar, or is having similar problems here is the simple code I ended up with.

Copy to clipboard

    player_vec = ([player.worldPosition.x, player.worldPosition.y, player.worldPosition.z - .5])

    ground_target = ([player.worldPosition.x,player.worldPosition.y,player.worldPosition.z - 20])

    ray = player.rayCast(ground_target, player_vec, 2, '', 0, 0, 0)

    bge.render.drawLine(player_vec,ray[1],(1,1,0))#debug visual aid

    if ray[1]:

        tempVec = ray[1]

        player.worldPosition.z = tempVec.z + 1.2

        if forward == pressed:

            player.applyMovement((0.2,0,0), True)

        if back == pressed:

            player.applyMovement((-0.15,0,0), True)

        if left == pressed:

            player.applyRotation((0,0,.05), True)

        if right == pressed:

            player.applyRotation((0,0,-.05), True)

I will update the first thread.

Reagrads from

Vidya Vox jio4gvoice

Log in or register to post comments